Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,45 +0,0 @@
|
|||
PROC ordered = (STRING s)BOOL:
|
||||
BEGIN
|
||||
FOR i TO UPB s - 1 DO IF s[i] > s[i+1] THEN return false FI OD;
|
||||
TRUE EXIT
|
||||
return false: FALSE
|
||||
END;
|
||||
|
||||
IF FILE input file;
|
||||
STRING file name = "unixdict.txt";
|
||||
open(input file, file name, stand in channel) /= 0
|
||||
THEN
|
||||
print(("Unable to open file """ + file name + """", newline))
|
||||
ELSE
|
||||
BOOL at eof := FALSE;
|
||||
on logical file end (input file, (REF FILE f)BOOL: at eof := TRUE);
|
||||
|
||||
FLEX [1:0] STRING words;
|
||||
INT idx := 1;
|
||||
INT max length := 0;
|
||||
|
||||
WHILE NOT at eof
|
||||
DO
|
||||
STRING word;
|
||||
get(input file, (word, newline));
|
||||
IF UPB word >= max length
|
||||
THEN IF ordered(word)
|
||||
THEN
|
||||
max length := UPB word;
|
||||
IF idx > UPB words
|
||||
THEN
|
||||
[1 : UPB words + 20] STRING tmp;
|
||||
tmp[1 : UPB words] := words;
|
||||
words := tmp
|
||||
FI;
|
||||
words[idx] := word;
|
||||
idx +:= 1
|
||||
FI
|
||||
FI
|
||||
OD;
|
||||
print(("Maximum length of ordered words: ", whole(max length, -4), newline));
|
||||
FOR i TO idx-1
|
||||
DO
|
||||
IF UPB words[i] = max length THEN print((words[i], newline)) FI
|
||||
OD
|
||||
FI
|
||||
|
|
@ -1,36 +1,36 @@
|
|||
BEGIN {
|
||||
abc = "abcdefghijklmnopqrstuvwxyz"
|
||||
abc = "abcdefghijklmnopqrstuvwxyz"
|
||||
}
|
||||
|
||||
{
|
||||
# Check if this line is an ordered word.
|
||||
ordered = 1 # true
|
||||
left = -1
|
||||
for (i = 1; i <= length($0); i++) {
|
||||
right = index(abc, substr($0, i, 1))
|
||||
if (right == 0 || left > right) {
|
||||
ordered = 0 # false
|
||||
break
|
||||
}
|
||||
left = right
|
||||
}
|
||||
# Check if this line is an ordered word.
|
||||
ordered = 1 # true
|
||||
left = -1
|
||||
for (i = 1; i <= length($0); i++) {
|
||||
right = index(abc, substr($0, i, 1))
|
||||
if (right == 0 || left > right) {
|
||||
ordered = 0 # false
|
||||
break
|
||||
}
|
||||
left = right
|
||||
}
|
||||
|
||||
if (ordered) {
|
||||
score = length($0)
|
||||
if (score > best["score"]) {
|
||||
# Reset the list of best ordered words.
|
||||
best["score"] = score
|
||||
best["count"] = 1
|
||||
best[1] = $0
|
||||
} else if (score == best["score"]) {
|
||||
# Add this word to the list.
|
||||
best[++best["count"]] = $0
|
||||
}
|
||||
}
|
||||
if (ordered) {
|
||||
score = length($0)
|
||||
if (score > best["score"]) {
|
||||
# Reset the list of best ordered words.
|
||||
best["score"] = score
|
||||
best["count"] = 1
|
||||
best[1] = $0
|
||||
} else if (score == best["score"]) {
|
||||
# Add this word to the list.
|
||||
best[++best["count"]] = $0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
# Print the list of best ordered words.
|
||||
for (i = 1; i <= best["count"]; i++)
|
||||
print best[i]
|
||||
# Print the list of best ordered words.
|
||||
for (i = 1; i <= best["count"]; i++)
|
||||
print best[i]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Containers.Indefinite_Vectors;
|
||||
use Ada.Text_IO;
|
||||
|
||||
procedure Ordered_Words is
|
||||
package Word_Vectors is new Ada.Containers.Indefinite_Vectors
|
||||
(Index_Type => Positive, Element_Type => String);
|
||||
use Word_Vectors;
|
||||
File : File_Type;
|
||||
Ordered_Words : Vector;
|
||||
Max_Length : Positive := 1;
|
||||
begin
|
||||
Open (File, In_File, "unixdict.txt");
|
||||
while not End_Of_File (File) loop
|
||||
declare
|
||||
Word : String := Get_Line (File);
|
||||
begin
|
||||
if (for all i in Word'First..Word'Last-1 => Word (i) <= Word(i+1)) then
|
||||
if Word'Length > Max_Length then
|
||||
Max_Length := Word'Length;
|
||||
Ordered_Words.Clear;
|
||||
Ordered_Words.Append (Word);
|
||||
elsif Word'Length = Max_Length then
|
||||
Ordered_Words.Append (Word);
|
||||
end if;
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
for Word of Ordered_Words loop
|
||||
Put_Line (Word);
|
||||
end loop;
|
||||
Close (File);
|
||||
end Ordered_Words;
|
||||
|
|
@ -2,7 +2,7 @@ ordered?: function [w]->
|
|||
w = join sort split w
|
||||
|
||||
words: read.lines relative "unixdict.txt"
|
||||
ret: new []
|
||||
ret: []
|
||||
loop words 'wrd [
|
||||
if ordered? wrd ->
|
||||
'ret ++ #[w: wrd l: size wrd]
|
||||
|
|
|
|||
|
|
@ -9,46 +9,46 @@
|
|||
|
||||
int ordered(char *s, char **end)
|
||||
{
|
||||
int r = 1;
|
||||
while (*++s != '\n' && *s != '\r' && *s != '\0')
|
||||
if (s[0] < s[-1]) r = 0;
|
||||
int r = 1;
|
||||
while (*++s != '\n' && *s != '\r' && *s != '\0')
|
||||
if (s[0] < s[-1]) r = 0;
|
||||
|
||||
*end = s;
|
||||
return r;
|
||||
*end = s;
|
||||
return r;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char *buf, *word, *end, *tail;
|
||||
struct stat st;
|
||||
int longest = 0, len, fd;
|
||||
char *buf, *word, *end, *tail;
|
||||
struct stat st;
|
||||
int longest = 0, len, fd;
|
||||
|
||||
if ((fd = open("unixdict.txt", O_RDONLY)) == -1) err(1, "read error");
|
||||
if ((fd = open("unixdict.txt", O_RDONLY)) == -1) err(1, "read error");
|
||||
|
||||
fstat(fd, &st);
|
||||
if (!(buf = mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)))
|
||||
err(1, "mmap");
|
||||
fstat(fd, &st);
|
||||
if (!(buf = mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)))
|
||||
err(1, "mmap");
|
||||
|
||||
for (word = end = buf; end < buf + st.st_size; word = end) {
|
||||
while (*word == '\r' || *word == '\n') word++;
|
||||
if (!ordered(word, &end)) continue;
|
||||
if ((len = end - word + 1) < longest) continue;
|
||||
if (len > longest) {
|
||||
tail = buf; /* longer words found; reset out buffer */
|
||||
longest = len;
|
||||
}
|
||||
/* use the same mmap'd region to store output. because of MAP_PRIVATE,
|
||||
* change will not go back to file. mmap is copy on write, and we are using
|
||||
* only the head space to store output, so kernel doesn't need to copy more
|
||||
* than the words we saved--in this case, one page tops.
|
||||
*/
|
||||
memcpy(tail, word, len);
|
||||
tail += len;
|
||||
*tail = '\0';
|
||||
}
|
||||
printf(buf);
|
||||
for (word = end = buf; end < buf + st.st_size; word = end) {
|
||||
while (*word == '\r' || *word == '\n') word++;
|
||||
if (!ordered(word, &end)) continue;
|
||||
if ((len = end - word + 1) < longest) continue;
|
||||
if (len > longest) {
|
||||
tail = buf; /* longer words found; reset out buffer */
|
||||
longest = len;
|
||||
}
|
||||
/* use the same mmap'd region to store output. because of MAP_PRIVATE,
|
||||
* change will not go back to file. mmap is copy on write, and we are using
|
||||
* only the head space to store output, so kernel doesn't need to copy more
|
||||
* than the words we saved--in this case, one page tops.
|
||||
*/
|
||||
memcpy(tail, word, len);
|
||||
tail += len;
|
||||
*tail = '\0';
|
||||
}
|
||||
printf(buf);
|
||||
|
||||
munmap(buf, st.st_size);
|
||||
close(fd);
|
||||
return 0;
|
||||
munmap(buf, st.st_size);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. ABC-WORDS.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT DICT ASSIGN TO DISK
|
||||
ORGANIZATION LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD DICT
|
||||
LABEL RECORD STANDARD
|
||||
VALUE OF FILE-ID IS "unixdict.txt".
|
||||
01 ENTRY.
|
||||
03 WORD PIC X(32).
|
||||
03 LETTERS PIC X OCCURS 32 TIMES, REDEFINES WORD.
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 LEN PIC 99.
|
||||
01 MAXLEN PIC 99 VALUE 0.
|
||||
01 I PIC 99.
|
||||
01 OK-FLAG PIC X.
|
||||
88 OK VALUE '*'.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
BEGIN.
|
||||
OPEN INPUT DICT.
|
||||
|
||||
FIND-LONGEST-WORD.
|
||||
READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
|
||||
PERFORM CHECK-WORD.
|
||||
GO TO FIND-LONGEST-WORD.
|
||||
|
||||
PRINT-LONGEST-WORDS.
|
||||
ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
|
||||
OPEN INPUT DICT.
|
||||
|
||||
READ-WORDS.
|
||||
READ DICT, AT END CLOSE DICT, STOP RUN.
|
||||
PERFORM CHECK-WORD.
|
||||
GO TO READ-WORDS.
|
||||
|
||||
CHECK-WORD.
|
||||
MOVE ZERO TO LEN.
|
||||
INSPECT WORD TALLYING LEN
|
||||
FOR CHARACTERS BEFORE INITIAL SPACE.
|
||||
MOVE '*' TO OK-FLAG.
|
||||
PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
|
||||
UNTIL NOT OK OR I IS GREATER THAN LEN.
|
||||
IF OK, PERFORM DO-WORD.
|
||||
|
||||
CHECK-CHAR-PAIR.
|
||||
IF LETTERS(I - 1) IS GREATER THAN LETTERS(I),
|
||||
MOVE SPACE TO OK-FLAG.
|
||||
|
||||
DO-WORD SECTION.
|
||||
VALID-WORD.
|
||||
GO TO CHECK-LENGTH.
|
||||
CHECK-LENGTH.
|
||||
IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
|
||||
GO TO DONE.
|
||||
SHOW-WORD.
|
||||
IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
|
||||
DONE.
|
||||
EXIT.
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
(apply #'char<= (coerce word 'list)))
|
||||
|
||||
(let* ((words (uiop:read-file-lines "unixdict.txt"))
|
||||
(ordered (delete-if-not #'orderedp words))
|
||||
(maxlen (apply #'max (mapcar #'length ordered)))
|
||||
(result (delete-if-not (lambda (l) (= l maxlen)) ordered :key #'length)))
|
||||
(ordered (delete-if-not #'orderedp words))
|
||||
(maxlen (apply #'max (mapcar #'length ordered)))
|
||||
(result (delete-if-not (lambda (l) (= l maxlen)) ordered :key #'length)))
|
||||
(format t "~{~A~^, ~}" result))
|
||||
|
|
|
|||
|
|
@ -5,15 +5,15 @@
|
|||
(define (ordre words)
|
||||
(define wl 0)
|
||||
(define s 's)
|
||||
(for/fold (len 0) ((w words))
|
||||
(set! wl (string-length w))
|
||||
#:continue (< wl len)
|
||||
#:when (ordered? w)
|
||||
#:continue (and (= len wl) (push s w))
|
||||
(push (stack s) w) ;; start a new list of length wl
|
||||
wl)
|
||||
(stack->list s))
|
||||
|
||||
(for/fold (len 0) ((w words))
|
||||
(set! wl (string-length w))
|
||||
#:continue (< wl len)
|
||||
#:when (ordered? w)
|
||||
#:continue (and (= len wl) (push s w))
|
||||
(push (stack s) w) ;; start a new list of length wl
|
||||
wl)
|
||||
(stack->list s))
|
||||
|
||||
;; output
|
||||
(load 'unixdict)
|
||||
(ordre (text-parse unixdict))
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
(defun order-alphabetically (str)
|
||||
"Put letters in STR in alphabetical order."
|
||||
;; split STR into list of individual letters in alphabetical order
|
||||
;; and then join the letters back into one string
|
||||
(apply #'concat (sort (split-string str "" t) #'string<)))
|
||||
|
||||
(defun ordered-alphabetically-p (str)
|
||||
"Test if letters STR are in alphabetical order."
|
||||
(string= (order-alphabetically str) str))
|
||||
|
||||
|
||||
(defun make-list-of-ordered-words (word-list)
|
||||
"Create subset of ordered words from words in WORD-LIST."
|
||||
(let ((ordered-words))
|
||||
(dolist (one-word word-list)
|
||||
(when (ordered-alphabetically-p one-word)
|
||||
(push (format "%s" one-word) ordered-words)))
|
||||
ordered-words))
|
||||
|
||||
(defun list-length-words (word-list)
|
||||
"From the words in WORD-LIST, create list of pairs of words and their length."
|
||||
(let ((paired-list)
|
||||
(temp-pair))
|
||||
(dolist (one-word word-list)
|
||||
(setq temp-pair (list (length one-word) one-word))
|
||||
(push temp-pair paired-list))
|
||||
paired-list))
|
||||
|
||||
(defun create-list-of-numbers (numbers-and-words-list)
|
||||
"Create list of numbers from NUMBERS-AND-WORDS-LIST."
|
||||
(let ((list-of-numbers))
|
||||
(dolist (one-pair numbers-and-words-list)
|
||||
(push (car one-pair) list-of-numbers))
|
||||
list-of-numbers))
|
||||
|
||||
(defun get-largest-number (numbers-and-words-list)
|
||||
"Find largest number in NUMBERS-AND-WORDS-LIST."
|
||||
(let ((list-of-numbers))
|
||||
(setq list-of-numbers (create-list-of-numbers numbers-and-words-list))
|
||||
(apply #'max list-of-numbers)))
|
||||
|
||||
(defun make-list-matching-words (largest-number numbers-and-words-list)
|
||||
"List words whose length equals LARGEST-NUMBER."
|
||||
(dolist (number-and-word-pair numbers-and-words-list)
|
||||
;; test if number in NUMBER-AND-WORD-PAIR matches
|
||||
;; LARGEST-NUMBER
|
||||
(when (= (nth 0 number-and-word-pair) largest-number)
|
||||
;; insert the original word
|
||||
(insert (format "%s " (nth 1 number-and-word-pair)))))
|
||||
(insert "\n"))
|
||||
|
||||
(defun get-longest-ordered-words ()
|
||||
"Find the longest ordered words in file wordlist.txt.
|
||||
A word is an ordered word if its letters are in alphabetical order."
|
||||
(let ((all-word-list)
|
||||
(just-ordered-words)
|
||||
(lengths-and-words)
|
||||
(longest-word-length))
|
||||
;; Path below needs to be adapted to individual case
|
||||
(find-file "~/Documents/Elisp/wordlist.txt")
|
||||
(beginning-of-buffer)
|
||||
;; Create list of all words in file
|
||||
(setq all-word-list (split-string (buffer-string) "\n"))
|
||||
;; Test if a word is an ordered word, if so add to JUST-ORDERED-WORDS
|
||||
(dolist (one-word all-word-list)
|
||||
(if (ordered-alphabetically-p one-word)
|
||||
(push one-word just-ordered-words)))
|
||||
;; pair word lengths with ordered words
|
||||
(setq lengths-and-words (list-length-words just-ordered-words))
|
||||
;; Get the longest word length
|
||||
(setq longest-word (get-largest-number lengths-and-words))
|
||||
(find-file "longest-ordered-words")
|
||||
(erase-buffer)
|
||||
;; list the longest ordered words
|
||||
(make-list-matching-words longest-word lengths-and-words)))
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
include misc.e
|
||||
|
||||
type ordered(sequence s)
|
||||
for i = 1 to length(s)-1 do
|
||||
-- assume all items in the sequence are atoms
|
||||
if s[i]>s[i+1] then
|
||||
return 0
|
||||
end if
|
||||
end for
|
||||
return 1
|
||||
end type
|
||||
|
||||
integer maxlen
|
||||
sequence words
|
||||
object word
|
||||
constant fn = open("unixdict.txt","r")
|
||||
maxlen = -1
|
||||
|
||||
while 1 do
|
||||
word = gets(fn)
|
||||
if atom(word) then
|
||||
exit
|
||||
end if
|
||||
word = word[1..$-1] -- truncate new-line
|
||||
if length(word) >= maxlen and ordered(word) then
|
||||
if length(word) > maxlen then
|
||||
maxlen = length(word)
|
||||
words = {}
|
||||
end if
|
||||
words = append(words,word)
|
||||
end if
|
||||
end while
|
||||
|
||||
close(fn)
|
||||
|
||||
pretty_print(1,words,{2})
|
||||
|
|
@ -3,76 +3,76 @@
|
|||
!***************************************************************************************
|
||||
implicit none
|
||||
|
||||
!the dictionary file:
|
||||
integer,parameter :: file_unit = 1000
|
||||
character(len=*),parameter :: filename = 'unixdict.txt'
|
||||
!the dictionary file:
|
||||
integer,parameter :: file_unit = 1000
|
||||
character(len=*),parameter :: filename = 'unixdict.txt'
|
||||
|
||||
!maximum number of characters in a word:
|
||||
integer,parameter :: max_chars = 50
|
||||
!maximum number of characters in a word:
|
||||
integer,parameter :: max_chars = 50
|
||||
|
||||
type word
|
||||
character(len=max_chars) :: str !the word from the dictionary
|
||||
integer :: n = 0 !length of this word
|
||||
logical :: ordered = .false. !if it is an ordered word
|
||||
end type word
|
||||
type word
|
||||
character(len=max_chars) :: str !the word from the dictionary
|
||||
integer :: n = 0 !length of this word
|
||||
logical :: ordered = .false. !if it is an ordered word
|
||||
end type word
|
||||
|
||||
!the dictionary structure:
|
||||
type(word),dimension(:),allocatable :: dict
|
||||
!the dictionary structure:
|
||||
type(word),dimension(:),allocatable :: dict
|
||||
|
||||
contains
|
||||
contains
|
||||
!***************************************************************************************
|
||||
|
||||
!******************************************************************************
|
||||
function count_lines_in_file(fid) result(n_lines)
|
||||
!******************************************************************************
|
||||
implicit none
|
||||
!******************************************************************************
|
||||
function count_lines_in_file(fid) result(n_lines)
|
||||
!******************************************************************************
|
||||
implicit none
|
||||
|
||||
integer :: n_lines
|
||||
integer,intent(in) :: fid
|
||||
character(len=1) :: tmp
|
||||
integer :: i
|
||||
integer :: ios
|
||||
integer :: n_lines
|
||||
integer,intent(in) :: fid
|
||||
character(len=1) :: tmp
|
||||
integer :: i
|
||||
integer :: ios
|
||||
|
||||
!the file is assumed to be open already.
|
||||
!the file is assumed to be open already.
|
||||
|
||||
rewind(fid) !rewind to beginning of the file
|
||||
rewind(fid) !rewind to beginning of the file
|
||||
|
||||
n_lines = 0
|
||||
do !read each line until the end of the file.
|
||||
read(fid,'(A1)',iostat=ios) tmp
|
||||
if (ios < 0) exit !End of file
|
||||
n_lines = n_lines + 1 !row counter
|
||||
end do
|
||||
n_lines = 0
|
||||
do !read each line until the end of the file.
|
||||
read(fid,'(A1)',iostat=ios) tmp
|
||||
if (ios < 0) exit !End of file
|
||||
n_lines = n_lines + 1 !row counter
|
||||
end do
|
||||
|
||||
rewind(fid) !rewind to beginning of the file
|
||||
rewind(fid) !rewind to beginning of the file
|
||||
|
||||
!******************************************************************************
|
||||
end function count_lines_in_file
|
||||
!******************************************************************************
|
||||
!******************************************************************************
|
||||
end function count_lines_in_file
|
||||
!******************************************************************************
|
||||
|
||||
!******************************************************************************
|
||||
pure elemental function ordered_word(word) result(yn)
|
||||
!******************************************************************************
|
||||
! turns true if word is an ordered word, false if it is not.
|
||||
!******************************************************************************
|
||||
|
||||
implicit none
|
||||
character(len=*),intent(in) :: word
|
||||
logical :: yn
|
||||
|
||||
integer :: i
|
||||
|
||||
yn = .true.
|
||||
do i=1,len_trim(word)-1
|
||||
if (ichar(word(i+1:i+1))<ichar(word(i:i))) then
|
||||
yn = .false.
|
||||
exit
|
||||
end if
|
||||
end do
|
||||
|
||||
!******************************************************************************
|
||||
end function ordered_word
|
||||
!******************************************************************************
|
||||
!******************************************************************************
|
||||
pure elemental function ordered_word(word) result(yn)
|
||||
!******************************************************************************
|
||||
! turns true if word is an ordered word, false if it is not.
|
||||
!******************************************************************************
|
||||
|
||||
implicit none
|
||||
character(len=*),intent(in) :: word
|
||||
logical :: yn
|
||||
|
||||
integer :: i
|
||||
|
||||
yn = .true.
|
||||
do i=1,len_trim(word)-1
|
||||
if (ichar(word(i+1:i+1))<ichar(word(i:i))) then
|
||||
yn = .false.
|
||||
exit
|
||||
end if
|
||||
end do
|
||||
|
||||
!******************************************************************************
|
||||
end function ordered_word
|
||||
!******************************************************************************
|
||||
|
||||
!***************************************************************************************
|
||||
end module ordered_module
|
||||
|
|
@ -84,29 +84,29 @@
|
|||
use ordered_module
|
||||
implicit none
|
||||
|
||||
integer :: i,n,n_max
|
||||
integer :: i,n,n_max
|
||||
|
||||
!open the dictionary and read in all the words:
|
||||
open(unit=file_unit,file=filename) !open the file
|
||||
n = count_lines_in_file(file_unit) !count lines in the file
|
||||
allocate(dict(n)) !allocate dictionary structure
|
||||
do i=1,n !
|
||||
read(file_unit,'(A)') dict(i)%str !each line is a word in the dictionary
|
||||
dict(i)%n = len_trim(dict(i)%str) !save word length
|
||||
end do
|
||||
close(file_unit) !close the file
|
||||
!open the dictionary and read in all the words:
|
||||
open(unit=file_unit,file=filename) !open the file
|
||||
n = count_lines_in_file(file_unit) !count lines in the file
|
||||
allocate(dict(n)) !allocate dictionary structure
|
||||
do i=1,n !
|
||||
read(file_unit,'(A)') dict(i)%str !each line is a word in the dictionary
|
||||
dict(i)%n = len_trim(dict(i)%str) !save word length
|
||||
end do
|
||||
close(file_unit) !close the file
|
||||
|
||||
!use elemental procedure to get ordered words:
|
||||
dict%ordered = ordered_word(dict%str)
|
||||
!use elemental procedure to get ordered words:
|
||||
dict%ordered = ordered_word(dict%str)
|
||||
|
||||
!max length of an ordered word:
|
||||
n_max = maxval(dict%n, mask=dict%ordered)
|
||||
|
||||
!write the output:
|
||||
do i=1,n
|
||||
if (dict(i)%ordered .and. dict(i)%n==n_max) write(*,'(A,A)',advance='NO') trim(dict(i)%str),' '
|
||||
end do
|
||||
write(*,*) ''
|
||||
!max length of an ordered word:
|
||||
n_max = maxval(dict%n, mask=dict%ordered)
|
||||
|
||||
!write the output:
|
||||
do i=1,n
|
||||
if (dict(i)%ordered .and. dict(i)%n==n_max) write(*,'(A,A)',advance='NO') trim(dict(i)%str),' '
|
||||
end do
|
||||
write(*,*) ''
|
||||
|
||||
!****************************************************
|
||||
end program main
|
||||
|
|
|
|||
|
|
@ -9,35 +9,35 @@ import java.util.List;
|
|||
|
||||
public class Ordered {
|
||||
|
||||
private static boolean isOrderedWord(String word){
|
||||
char[] sortedWord = word.toCharArray();
|
||||
Arrays.sort(sortedWord);
|
||||
return word.equals(new String(sortedWord));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
List<String> orderedWords = new LinkedList<String>();
|
||||
BufferedReader in = new BufferedReader(new FileReader(args[0]));
|
||||
while(in.ready()){
|
||||
String word = in.readLine();
|
||||
if(isOrderedWord(word)) orderedWords.add(word);
|
||||
}
|
||||
in.close();
|
||||
|
||||
Collections.<String>sort(orderedWords, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return new Integer(o2.length()).compareTo(o1.length());
|
||||
}
|
||||
});
|
||||
|
||||
int maxLen = orderedWords.get(0).length();
|
||||
for(String word: orderedWords){
|
||||
if(word.length() == maxLen){
|
||||
System.out.println(word);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static boolean isOrderedWord(String word){
|
||||
char[] sortedWord = word.toCharArray();
|
||||
Arrays.sort(sortedWord);
|
||||
return word.equals(new String(sortedWord));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
List<String> orderedWords = new LinkedList<String>();
|
||||
BufferedReader in = new BufferedReader(new FileReader(args[0]));
|
||||
while(in.ready()){
|
||||
String word = in.readLine();
|
||||
if(isOrderedWord(word)) orderedWords.add(word);
|
||||
}
|
||||
in.close();
|
||||
|
||||
Collections.<String>sort(orderedWords, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return new Integer(o2.length()).compareTo(o1.length());
|
||||
}
|
||||
});
|
||||
|
||||
int maxLen = orderedWords.get(0).length();
|
||||
for(String word: orderedWords){
|
||||
if(word.length() == maxLen){
|
||||
System.out.println(word);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,21 +5,21 @@ import java.util.List;
|
|||
|
||||
public final class OrderedWords {
|
||||
|
||||
public static void main(String[] aArgs) throws IOException {
|
||||
List<String> ordered = Files.lines(Path.of("unixdict.txt"))
|
||||
.filter( word -> isOrdered(word) ).toList();
|
||||
|
||||
final int maxLength = ordered.stream().map( word -> word.length() ).max(Integer::compare).get();
|
||||
ordered.stream().filter( word -> word.length() == maxLength ).forEach(System.out::println);
|
||||
}
|
||||
|
||||
private static boolean isOrdered(String aWord) {
|
||||
return aWord.chars()
|
||||
.mapToObj( i -> (char) i )
|
||||
.sorted()
|
||||
.map(String::valueOf)
|
||||
.reduce("", String::concat)
|
||||
.equals(aWord);
|
||||
}
|
||||
public static void main(String[] aArgs) throws IOException {
|
||||
List<String> ordered = Files.lines(Path.of("unixdict.txt"))
|
||||
.filter( word -> isOrdered(word) ).toList();
|
||||
|
||||
final int maxLength = ordered.stream().map( word -> word.length() ).max(Integer::compare).get();
|
||||
ordered.stream().filter( word -> word.length() == maxLength ).forEach(System.out::println);
|
||||
}
|
||||
|
||||
private static boolean isOrdered(String aWord) {
|
||||
return aWord.chars()
|
||||
.mapToObj( i -> (char) i )
|
||||
.sorted()
|
||||
.map(String::valueOf)
|
||||
.reduce("", String::concat)
|
||||
.equals(aWord);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
local(f = file('unixdict.txt'), words = array, ordered = array, maxleng = 0)
|
||||
#f->dowithclose => {
|
||||
#f->foreachLine => {
|
||||
#words->insert(#1)
|
||||
}
|
||||
#f->foreachLine => {
|
||||
#words->insert(#1)
|
||||
}
|
||||
}
|
||||
with w in #words
|
||||
do => {
|
||||
local(tosort = #w->asString->values)
|
||||
#tosort->sort
|
||||
if(#w->asString == #tosort->join('')) => {
|
||||
#ordered->insert(#w->asString)
|
||||
#w->asString->size > #maxleng ? #maxleng = #w->asString->size
|
||||
}
|
||||
local(tosort = #w->asString->values)
|
||||
#tosort->sort
|
||||
if(#w->asString == #tosort->join('')) => {
|
||||
#ordered->insert(#w->asString)
|
||||
#w->asString->size > #maxleng ? #maxleng = #w->asString->size
|
||||
}
|
||||
}
|
||||
with w in #ordered
|
||||
where #w->size == #maxleng
|
||||
|
|
|
|||
|
|
@ -6,21 +6,21 @@ list = {}
|
|||
for w in fp:lines() do
|
||||
ordered = true
|
||||
for l = 2, string.len(w) do
|
||||
if string.byte( w, l-1 ) > string.byte( w, l ) then
|
||||
ordered = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if string.byte( w, l-1 ) > string.byte( w, l ) then
|
||||
ordered = false
|
||||
break
|
||||
end -- if
|
||||
end -- for
|
||||
if ordered then
|
||||
if string.len(w) > maxlen then
|
||||
list = {}
|
||||
list[1] = w
|
||||
maxlen = string.len(w)
|
||||
elseif string.len(w) == maxlen then
|
||||
list[#list+1] = w
|
||||
end
|
||||
end
|
||||
end
|
||||
if string.len(w) > maxlen then
|
||||
list = {}
|
||||
list[1] = w
|
||||
maxlen = string.len(w)
|
||||
elseif string.len(w) == maxlen then
|
||||
list[#list+1] = w
|
||||
end -- if
|
||||
end -- if
|
||||
end -- for
|
||||
|
||||
for _, w in pairs(list) do
|
||||
print( w )
|
||||
|
|
|
|||
|
|
@ -1,38 +1,38 @@
|
|||
module Ordered_Words {
|
||||
orderword=lambda ->{
|
||||
buffer a as integer*30
|
||||
=lambda a (s as string) -> {
|
||||
if len(s)*2>len(a) then buffer a as integer*len(s)
|
||||
return a, 0:=s
|
||||
if len(s)=1 then =true: exit
|
||||
for i=1 to len(s)-1
|
||||
if a[i-1]>a[i] then break
|
||||
next i
|
||||
=true
|
||||
}
|
||||
}()
|
||||
max=2
|
||||
res=stack
|
||||
document a$
|
||||
load.doc a$, "unixdict.txt"
|
||||
k=doc.par(a$)
|
||||
i=0
|
||||
m=Paragraph(a$, 0)
|
||||
if forward(a$, m) then
|
||||
while m
|
||||
i++
|
||||
if i mod 20=1 then Print Over round(i/k*100,2);"%" : refresh
|
||||
word=paragraph$(a$, (m))
|
||||
if orderword(word) then
|
||||
if max<len(word) then max=len(word): res=stack
|
||||
if max=len(word) then stack res {data word}
|
||||
end if
|
||||
end while
|
||||
print
|
||||
end if
|
||||
open "outtxt.txt" for output as #f
|
||||
Print #f, "words:", array(res)#str$(" ")
|
||||
close #f
|
||||
win dir$+"outtxt.txt"
|
||||
orderword=lambda ->{
|
||||
buffer a as integer*30
|
||||
=lambda a (s as string) -> {
|
||||
if len(s)*2>len(a) then buffer a as integer*len(s)
|
||||
return a, 0:=s
|
||||
if len(s)=1 then =true: exit
|
||||
for i=1 to len(s)-1
|
||||
if a[i-1]>a[i] then break
|
||||
next i
|
||||
=true
|
||||
}
|
||||
}()
|
||||
max=2
|
||||
res=stack
|
||||
document a$
|
||||
load.doc a$, "unixdict.txt"
|
||||
k=doc.par(a$)
|
||||
i=0
|
||||
m=Paragraph(a$, 0)
|
||||
if forward(a$, m) then
|
||||
while m
|
||||
i++
|
||||
if i mod 20=1 then Print Over round(i/k*100,2);"%" : refresh
|
||||
word=paragraph$(a$, (m))
|
||||
if orderword(word) then
|
||||
if max<len(word) then max=len(word): res=stack
|
||||
if max=len(word) then stack res {data word}
|
||||
end if
|
||||
end while
|
||||
print
|
||||
end if
|
||||
open "outtxt.txt" for output as #f
|
||||
Print #f, "words:", array(res)#str$(" ")
|
||||
close #f
|
||||
win dir$+"outtxt.txt"
|
||||
}
|
||||
Ordered_Words
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ while ~feof(fid)
|
|||
if any(diff(abs(str))<0) continue; end;
|
||||
|
||||
if length(str)>maxlen,
|
||||
list = {str};
|
||||
maxlen = length(str);
|
||||
list = {str};
|
||||
maxlen = length(str);
|
||||
elseif length(str)==maxlen,
|
||||
list{end+1} = str;
|
||||
list{end+1} = str;
|
||||
end;
|
||||
end
|
||||
fclose(fid);
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ longest := 0:
|
|||
words := Array():
|
||||
i := 1:
|
||||
for word in lst do
|
||||
if StringTools:-IsSorted(word) then
|
||||
len := StringTools:-Length(word):
|
||||
if len > longest then
|
||||
longest := len:
|
||||
words := Array():
|
||||
words(1) := word:
|
||||
i := 2:
|
||||
elif len = longest then
|
||||
words(i) := word:
|
||||
i++:
|
||||
end if;
|
||||
end if;
|
||||
if StringTools:-IsSorted(word) then
|
||||
len := StringTools:-Length(word):
|
||||
if len > longest then
|
||||
longest := len:
|
||||
words := Array():
|
||||
words(1) := word:
|
||||
i := 2:
|
||||
elif len = longest then
|
||||
words(i) := word:
|
||||
i++:
|
||||
end if;
|
||||
end if;
|
||||
end do;
|
||||
for word in words do print(word); end do;
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
$url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
|
||||
|
||||
(New-Object System.Net.WebClient).DownloadFile($url, "$env:TEMP\unixdict.txt")
|
||||
|
||||
$ordered = Get-Content -Path "$env:TEMP\unixdict.txt" |
|
||||
ForEach-Object {if (($_.ToCharArray() | Sort-Object) -join '' -eq $_) {$_}} |
|
||||
Group-Object -Property Length |
|
||||
Sort-Object -Property Name |
|
||||
Select-Object -Property @{Name="WordCount" ; Expression={$_.Count}},
|
||||
@{Name="WordLength"; Expression={[int]$_.Name}},
|
||||
@{Name="Words" ; Expression={$_.Group}} -Last 1
|
||||
|
||||
"There are {0} ordered words of the longest word length ({1} characters):`n`n{2}" -f $ordered.WordCount,
|
||||
$ordered.WordLength,
|
||||
($ordered.Words -join ", ")
|
||||
Remove-Item -Path "$env:TEMP\unixdict.txt" -Force -ErrorAction SilentlyContinue
|
||||
|
|
@ -2,43 +2,43 @@
|
|||
|
||||
ordered_words :-
|
||||
% we read the URL of the words
|
||||
http_open('http://www.puzzlers.org/pub/wordlists/unixdict.txt', In, []),
|
||||
read_file(In, [], Out),
|
||||
close(In),
|
||||
http_open('http://www.puzzlers.org/pub/wordlists/unixdict.txt', In, []),
|
||||
read_file(In, [], Out),
|
||||
close(In),
|
||||
|
||||
% we get a list of pairs key-value where key = Length and value = <list-of-its-codes>
|
||||
% this list must be sorted
|
||||
msort(Out, MOut),
|
||||
msort(Out, MOut),
|
||||
|
||||
group_pairs_by_key(MOut, POut),
|
||||
group_pairs_by_key(MOut, POut),
|
||||
|
||||
% we sorted this list in decreasing order of the length of values
|
||||
predsort(my_compare, POut, [_N-V | _OutSort]),
|
||||
maplist(mwritef, V).
|
||||
predsort(my_compare, POut, [_N-V | _OutSort]),
|
||||
maplist(mwritef, V).
|
||||
|
||||
|
||||
mwritef(V) :-
|
||||
writef('%s\n', [V]).
|
||||
writef('%s\n', [V]).
|
||||
|
||||
read_file(In, L, L1) :-
|
||||
read_line_to_codes(In, W),
|
||||
( W == end_of_file ->
|
||||
read_line_to_codes(In, W),
|
||||
( W == end_of_file ->
|
||||
% the file is read
|
||||
L1 = L
|
||||
;
|
||||
L1 = L
|
||||
;
|
||||
% we sort the list of codes of the line
|
||||
% and keep only the "goods word"
|
||||
( msort(W, W) ->
|
||||
length(W, N), L2 = [N-W | L], (len = 6 -> writef('%s\n', [W]); true)
|
||||
;
|
||||
L2 = L
|
||||
),
|
||||
% and keep only the "goods word"
|
||||
( msort(W, W) ->
|
||||
length(W, N), L2 = [N-W | L], (len = 6 -> writef('%s\n', [W]); true)
|
||||
;
|
||||
L2 = L
|
||||
),
|
||||
|
||||
% and we have the pair Key-Value in the result list
|
||||
read_file(In, L2, L1)).
|
||||
read_file(In, L2, L1)).
|
||||
|
||||
% predicate for sorting list of pairs Key-Values
|
||||
% if the lentgh of values is the same
|
||||
% we sort the keys in alhabetic order
|
||||
my_compare(R, K1-_V1, K2-_V2) :-
|
||||
( K1 < K2 -> R = >; K1 > K2 -> R = <; =).
|
||||
( K1 < K2 -> R = >; K1 > K2 -> R = <; =).
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
a$ = httpget$("http://www.puzzlers.org/pub/wordlists/unixdict.txt")
|
||||
j = 1
|
||||
i = instr(a$,chr$(10),j)
|
||||
a$ = httpget$("http://www.puzzlers.org/pub/wordlists/unixdict.txt")
|
||||
j = 1
|
||||
i = instr(a$,chr$(10),j)
|
||||
while i <> 0
|
||||
a1$ = mid$(a$,j,i-j)
|
||||
for k = 1 to len(a1$) - 1
|
||||
a1$ = mid$(a$,j,i-j)
|
||||
for k = 1 to len(a1$) - 1
|
||||
if mid$(a1$,k,1) > mid$(a1$,k+1,1) then goto [noWay]
|
||||
next k
|
||||
maxL = max(maxL,len(a1$))
|
||||
maxL = max(maxL,len(a1$))
|
||||
if len(a1$) >= maxL then a2$ = a2$ + a1$ + "||"
|
||||
[noWay]
|
||||
j = i + 1
|
||||
i = instr(a$,chr$(10),j)
|
||||
j = i + 1
|
||||
i = instr(a$,chr$(10),j)
|
||||
wend
|
||||
n = 1
|
||||
n = 1
|
||||
while word$(a2$,n,"||") <> ""
|
||||
a3$ = word$(a2$,n,"||")
|
||||
if len(a3$) = maxL then print a3$
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@
|
|||
(let loop ((char (read-char port)) (word '()) (result '(())))
|
||||
(cond
|
||||
((eof-object? char)
|
||||
(reverse (map (lambda (word) (apply string word)) result)))
|
||||
(reverse (map (lambda (word) (apply string word)) result)))
|
||||
((eq? #\newline char)
|
||||
(loop (read-char port) '()
|
||||
(let ((best-length (length (car result))) (word-length (length word)))
|
||||
(cond
|
||||
((or (< word-length best-length) (not (apply char>=? word))) result)
|
||||
((> word-length best-length) (list (reverse word)))
|
||||
(else (cons (reverse word) result))))))
|
||||
(loop (read-char port) '()
|
||||
(let ((best-length (length (car result))) (word-length (length word)))
|
||||
(cond
|
||||
((or (< word-length best-length) (not (apply char>=? word))) result)
|
||||
((> word-length best-length) (list (reverse word)))
|
||||
(else (cons (reverse word) result))))))
|
||||
(else (loop (read-char port) (cons char word) result))))))
|
||||
|
||||
(map (lambda (x)
|
||||
(begin
|
||||
(display x)
|
||||
(newline)))
|
||||
(display x)
|
||||
(newline)))
|
||||
sorted-words)
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ package require http
|
|||
proc chooseOrderedWords list {
|
||||
set len 0
|
||||
foreach word $list {
|
||||
# Condition to determine whether a word is ordered; are its characters
|
||||
# in sorted order?
|
||||
if {$word eq [join [lsort [split $word ""]] ""]} {
|
||||
if {[string length $word] > $len} {
|
||||
set len [string length $word]
|
||||
set orderedOfMaxLen {}
|
||||
}
|
||||
if {[string length $word] == $len} {
|
||||
lappend orderedOfMaxLen $word
|
||||
}
|
||||
}
|
||||
# Condition to determine whether a word is ordered; are its characters
|
||||
# in sorted order?
|
||||
if {$word eq [join [lsort [split $word ""]] ""]} {
|
||||
if {[string length $word] > $len} {
|
||||
set len [string length $word]
|
||||
set orderedOfMaxLen {}
|
||||
}
|
||||
if {[string length $word] == $len} {
|
||||
lappend orderedOfMaxLen $word
|
||||
}
|
||||
}
|
||||
}
|
||||
return $orderedOfMaxLen
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
&fras "unixdict.txt" # read file as string
|
||||
⊜□≠@\n. # split on newlines
|
||||
▽∵◇(/×≥0°\+utf). # keep ordered words
|
||||
▽=⊸/↥∵◇⧻. # keep all max length words
|
||||
# Experimental!
|
||||
# Grab the entire contents of the page as an array of bytes, then decode it into a string of text:
|
||||
°utf₈ &fetch "https://raw.githubusercontent.com/thundergnat/rc-run/refs/heads/master/rc/resources/unixdict.txt"
|
||||
°/$"_\n_" # Split the string into words by line breaks
|
||||
▽⊸≡◇(≍⊸⍆) # Keep the words that are sorted, i.e. have their letters in alphabetical order
|
||||
▽⊸(=⊸/↥≡◇⧻) # Keep the remaining words that are the longest
|
||||
≡◇&p # Print out each word individually
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
fn main() {
|
||||
words := os.read_file("./unixdict.txt") or {println(err) exit(-1)}.split_into_lines()
|
||||
mut longest_len := 0
|
||||
mut longest := []string{}
|
||||
mut u_word := []u8{}
|
||||
for word in words {
|
||||
for chars in word {u_word << chars}
|
||||
u_word.sort()
|
||||
if word.len > longest_len {
|
||||
if word == u_word.bytestr() {
|
||||
longest_len = word.len
|
||||
longest.clear()
|
||||
longest << word
|
||||
}
|
||||
}
|
||||
else if word.len == longest_len {
|
||||
if word == u_word.bytestr() {longest << word}
|
||||
}
|
||||
u_word.clear()
|
||||
}
|
||||
println("The ${longest.len} ordered words with the longest length (${longest_len}) are:")
|
||||
print(longest.join("\n"))
|
||||
mut longest_len := 0
|
||||
mut longest := []string{}
|
||||
mut u_word := []u8{}
|
||||
for word in words {
|
||||
for chars in word {u_word << chars}
|
||||
u_word.sort()
|
||||
if word.len > longest_len {
|
||||
if word == u_word.bytestr() {
|
||||
longest_len = word.len
|
||||
longest.clear()
|
||||
longest << word
|
||||
}
|
||||
}
|
||||
else if word.len == longest_len {
|
||||
if word == u_word.bytestr() {longest << word}
|
||||
}
|
||||
u_word.clear()
|
||||
}
|
||||
println("The ${longest.len} ordered words with the longest length (${longest_len}) are:")
|
||||
print(longest.join("\n"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
||||
Set infile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" &_
|
||||
"unixdict.txt",1)
|
||||
list = ""
|
||||
length = 0
|
||||
|
||||
Do Until inFile.AtEndOfStream
|
||||
line = infile.ReadLine
|
||||
If IsOrdered(line) Then
|
||||
If Len(line) > length Then
|
||||
length = Len(line)
|
||||
list = line & vbCrLf
|
||||
ElseIf Len(line) = length Then
|
||||
list = list & line & vbCrLf
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
|
||||
WScript.StdOut.Write list
|
||||
|
||||
Function IsOrdered(word)
|
||||
IsOrdered = True
|
||||
prev_val = 0
|
||||
For i = 1 To Len(word)
|
||||
If i = 1 Then
|
||||
prev_val = Asc(Mid(word,i,1))
|
||||
ElseIf Asc(Mid(word,i,1)) >= prev_val Then
|
||||
prev_val = Asc(Mid(word,i,1))
|
||||
Else
|
||||
IsOrdered = False
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue