langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,39 @@
/* NetRexx */
options replace format comments java crossref savelog symbols binary
unixdict = 'unixdict.txt'
do
wmax = Integer.MIN_VALUE
dwords = ArrayList()
inrdr = BufferedReader(FileReader(File(unixdict)))
loop label ln while inrdr.ready
dword = Rexx(inrdr.readLine).strip
if isOrdered(dword) then do
dwords.add(dword)
if dword.length > wmax then
wmax = dword.length
end
end ln
inrdr.close
witerator = dwords.listIterator
loop label wd while witerator.hasNext
dword = Rexx witerator.next
if dword.length < wmax then do
witerator.remove
end
end wd
dwords.trimToSize
say dwords.toString
catch ex = IOException
ex.printStackTrace
end
return
method isOrdered(dword = String) inheritable static binary returns boolean
wchars = dword.toCharArray
Arrays.sort(wchars)
return dword.equalsIgnoreCase(String(wchars))

View file

@ -0,0 +1,52 @@
let input_line_opt ic =
try Some(input_line ic)
with End_of_file -> None
(* load each line in a list *)
let read_lines ic =
let rec aux acc =
match input_line_opt ic with
| Some line -> aux (line :: acc)
| None -> (List.rev acc)
in
aux []
let char_list_of_string str =
let lst = ref [] in
String.iter (fun c -> lst := c :: !lst) str;
(List.rev !lst)
let is_ordered word =
let rec aux = function
| c1::c2::tl ->
if c1 <= c2
then aux (c2::tl)
else false
| c::[] -> true
| [] -> true (* should only occur with an empty string *)
in
aux (char_list_of_string word)
let longest_words words =
let res, _ =
List.fold_left
(fun (lst, n) word ->
let len = String.length word in
let comp = compare len n in
match lst, comp with
| lst, 0 -> ((word::lst), n) (* len = n *)
| lst, -1 -> (lst, n) (* len < n *)
| _, 1 -> ([word], len) (* len > n *)
| _ -> assert false
)
([""], 0) words
in
(List.rev res)
let () =
let ic = open_in "unixdict.txt" in
let words = read_lines ic in
let lower_words = List.map String.lowercase words in
let ordered_words = List.filter is_ordered lower_words in
let longest_ordered_words = longest_words ordered_words in
List.iter print_endline longest_ordered_words

View file

@ -0,0 +1,55 @@
order: procedure options (main); /* 24/11/2011 */
declare word character (20) varying;
declare word_list character (20) varying controlled;
declare max_length fixed binary;
declare input file;
open file (input) title ('/ORDER.DAT,TYPE(TEXT),RECSIZE(100)');
on endfile (input) go to completed_search;
max_length = 0;
do forever;
get file (input) edit (word) (L);
if length(word) > max_length then
do;
if in_order(word) then
do;
/* Get rid of any stockpiled shorter words. */
do while (allocation(word_list) > 0);
free word_list;
end;
/* Add the eligible word to the stockpile. */
allocate word_list;
word_list = word;
max_length = length(word);
end;
end;
else if max_length = length(word) then
do; /* we have an eligle word of the same (i.e., maximum) length. */
if in_order(word) then
do; /* Add it to the stockpile. */
allocate word_list;
word_list = word;
end;
end;
end;
completed_search:
put skip list ('There are ' || trim(allocation(word_list)) ||
' eligible words of length ' || trim(length(word)) || ':');
do while (allocation(word_list) > 0);
put skip list (word_list);
free word_list;
end;
/* Check that the letters of the word are in non-decreasing order of rank. */
in_order: procedure (word) returns (bit(1));
declare word character (*) varying;
declare i fixed binary;
do i = 1 to length(word)-1;
if substr(word, i, 1) > substr(word, i+1, 1) then return ('0'b);
end;
return ('1'b);
end in_order;
end order;

View file

@ -0,0 +1,12 @@
my @words;
my $maxlen = 0;
for slurp("unixdict.txt").lines {
if .chars >= $maxlen and [le] .comb {
if .chars > $maxlen {
@words = ();
$maxlen = .chars;
}
push @words, $_;
}
}
say ~@words;

View file

@ -0,0 +1,43 @@
Procedure.s sortLetters(*word.Character, wordLength) ;returns a string with the letters of a word sorted
Protected Dim letters.c(wordLength)
Protected *letAdr = @letters()
CopyMemoryString(*word, @*letAdr)
SortArray(letters(), #PB_Sort_Ascending, 0, wordLength - 1)
ProcedureReturn PeekS(@letters(), wordLength)
EndProcedure
Structure orderedWord
word.s
length.i
EndStructure
Define filename.s = "unixdict.txt", fileNum = 0, word.s
If OpenConsole()
NewList orderedWords.orderedWord()
If ReadFile(fileNum, filename)
While Not Eof(fileNum)
word = ReadString(fileNum)
If word = sortLetters(@word, Len(word))
AddElement(orderedWords())
orderedWords()\word = word
orderedWords()\length = Len(word)
EndIf
Wend
EndIf
SortStructuredList(orderedWords(), #PB_Sort_Ascending, OffsetOf(orderedWord\word), #PB_Sort_String)
SortStructuredList(orderedWords(), #PB_Sort_Descending, OffsetOf(orderedWord\length), #PB_Sort_integer)
Define maxLength
FirstElement(orderedWords())
maxLength = orderedWords()\length
ForEach orderedWords()
If orderedWords()\length = maxLength
Print(orderedWords()\word + " ")
EndIf
Next
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf

View file

@ -0,0 +1,20 @@
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
if mid$(a1$,k,1) > mid$(a1$,k+1,1) then goto [noWay]
next k
maxL = max(maxL,len(a1$))
if len(a1$) >= maxL then a2$ = a2$ + a1$ + "||"
[noWay]
j = i + 1
i = instr(a$,chr$(10),j)
wend
n = 1
while word$(a2$,n,"||") <> ""
a3$ = word$(a2$,n,"||")
if len(a3$) = maxL then print a3$
n = n + 1
wend

View file

@ -0,0 +1,52 @@
use io::ReaderUtil;
fn is_ordered(s: &str) -> bool {
let mut prev = '\x00';
for s.each_chari |i, c| {
if i > 0 && c < prev {
return false;
}
prev = c;
}
return true;
}
fn find_longest_ordered_words(dict: &[~str]) -> ~[~str] {
let mut result = ~[];
let mut longest_length = 0;
for dict.each |&s| {
if is_ordered(s) {
let n = s.len();
if n > longest_length {
longest_length = n;
vec::truncate(&mut result, 0);
}
if n == longest_length {
result.push(copy s);
}
}
}
return result;
}
fn main() {
let reader = match io::file_reader(&path::Path("unixdict.txt")) {
Ok(move r) => r,
Err(msg) => fail msg
};
let mut dict = ~[];
for reader.each_line |s| {
dict.push(str::from_slice(s));
}
let longest_ordered = find_longest_ordered_words(dict);
for longest_ordered.each |&s| {
io::println(s);
}
}

View file

@ -0,0 +1,49 @@
$ include "seed7_05.s7i";
const func boolean: isOrdered (in string: word) is func
result
var boolean: ordered is TRUE;
local
var integer: index is 0;
begin
for index range 1 to pred(length(word)) do
if word[index] > word[succ(index)] then
ordered := FALSE;
end if;
end for;
end func;
const proc: write (in array string: wordList) is func
local
var string: word is "";
begin
for word range wordList do
writeln(word);
end for;
end func;
const proc: main is func
local
var file: dictionary is STD_NULL;
var string: word is "";
var integer: length is 0;
var array string: wordList is 0 times "";
begin
dictionary := open("unixdict.txt", "r");
if dictionary <> STD_NULL then
readln(dictionary, word);
while not eof(dictionary) do
if isOrdered(lower(word)) then
if length(word) > length then
length := length(word);
wordList := [] (word);
elsif length(word) = length then
wordList &:= word;
end if;
end if;
readln(dictionary, word);
end while;
close(dictionary);
end if;
write(wordList);
end func;

View file

@ -0,0 +1,27 @@
$$ MODE TUSCRIPT
SET data = REQUEST ("http://www.puzzlers.org/pub/wordlists/unixdict.txt")
DICT orderdwords CREATE 99999
COMPILE
LOOP word=data
- "<%" = any token
SET letters=STRINGS (word,":<%:")
SET wordsignatur= ALPHA_SORT (letters)
IF (wordsignatur==letters) THEN
SET wordlength=LENGTH (word)
DICT orderdwords ADD/COUNT word,num,cnt,wordlength
ENDIF
ENDLOOP
DICT orderdwords UNLOAD words,num,cnt,wordlength
SET maxlength=MAX_LENGTH (words)
SET rtable=QUOTES (maxlength)
BUILD R_TABLE maxlength = rtable
SET index=FILTER_INDEX (wordlength,maxlength,-)
SET longestwords=SELECT (words,#index)
PRINT num," ordered words - max length is ",maxlength,":"
LOOP n,w=longestwords
SET n=CONCAT (n,"."), n=CENTER(n,4)
PRINT n,w
ENDLOOP
ENDCOMPILE

View file

@ -0,0 +1,5 @@
#import std
#show+
main = leql@bh$^ eql|= (ordered lleq)*~ unixdict_dot_txt

View file

@ -0,0 +1,76 @@
Public Sub orderedwords(fname As String)
' find ordered words in dict file that have the longest word length
' fname is the name of the input file
' the words are printed in the immediate window
' this subroutine uses boolean function IsOrdered
Dim word As String 'word to be tested
Dim l As Integer 'length of word
Dim wordlength As Integer 'current longest word length
Dim orderedword() As String 'dynamic array holding the ordered words with the current longest word length
Dim wordsfound As Integer 'length of the array orderedword()
On Error GoTo NotFound 'catch incorrect/missing file name
Open fname For Input As #1
On Error GoTo 0
'initialize
wordsfound = 0
wordlength = 0
'process file line per line
While Not EOF(1)
Line Input #1, word
If IsOrdered(word) Then 'found one, is it equal to or longer than current word length?
l = Len(word)
If l >= wordlength Then 'yes, so add to list or start a new list
If l > wordlength Then 'it's longer, we must start a new list
wordsfound = 1
wordlength = l
Else 'equal length, increase the list size
wordsfound = wordsfound + 1
End If
'add the word to the list
ReDim Preserve orderedword(wordsfound)
orderedword(wordsfound) = word
End If
End If
Wend
Close #1
'print the list
Debug.Print "Found"; wordsfound; "ordered words of length"; wordlength
For i = 1 To wordsfound
Debug.Print orderedword(i)
Next
Exit Sub
NotFound:
debug.print "Error: Cannot find or open file """ & fname & """!"
End Sub
Public Function IsOrdered(someWord As String) As Boolean
'true if letters in word are in ascending (ascii) sequence
Dim l As Integer 'length of someWord
Dim wordLcase As String 'the word in lower case
Dim ascStart As Integer 'ascii code of first char
Dim asc2 As Integer 'ascii code of next char
wordLcase = LCase(someWord) 'convert to lower case
l = Len(someWord)
IsOrdered = True
If l > 0 Then 'this skips empty string - it is considered ordered...
ascStart = Asc(Left$(wordLcase, 1))
For i = 2 To l
asc2 = Asc(Mid$(wordLcase, i, 1))
If asc2 < ascStart Then 'failure!
IsOrdered = False
Exit Function
End If
ascStart = asc2
Next i
End If
End Function

View file

@ -0,0 +1,26 @@
File_Open("unixdict.txt", BROWSE)
#1 = 2 // length of longest word found
Repeat (ALL) {
#2 = EOL_Pos-Cur_Pos // length of this word
if (#2 >= #1) {
#3 = 1 // flag: is ordered word
Char(1)
While (!At_EOL) {
if (Cur_Char < Cur_Char(-1)) {
#3 = 0 // not an ordered word
break
}
Char(1)
}
if (#3) { // ordered word found
if (#2 > #1) { // new longer word found
#1 = #2
Reg_Empty(10) // clear list
}
BOL Reg_Copy(10,1,APPEND) // add word to list
}
}
Line(1,ERRBREAK) // next word
}
Buf_Quit(OK) // close file
Reg_Type(10) // display results