September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,48 +1,32 @@
with Ada.Containers.Indefinite_Vectors;
with Ada.Text_IO;
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);
function Is_Ordered (The_Word : String) return Boolean is
Highest_Character : Character := 'a';
begin
for I in The_Word'Range loop
if The_Word(I) not in 'a' .. 'z' then
return False;
end if;
if The_Word(I) < Highest_Character then
return False;
end if;
Highest_Character := The_Word(I);
end loop;
return True;
end Is_Ordered;
procedure Print_Word (Position : Word_Vectors.Cursor) is
begin
Ada.Text_IO.Put_Line (Word_Vectors.Element (Position));
end Print_Word;
File : Ada.Text_IO.File_Type;
Ordered_Words : Word_Vectors.Vector;
use Word_Vectors;
File : File_Type;
Ordered_Words : Vector;
Max_Length : Positive := 1;
begin
Ada.Text_IO.Open (File, Ada.Text_IO.In_File, "unixdict.txt");
while not Ada.Text_IO.End_Of_File (File) loop
Open (File, In_File, "unixdict.txt");
while not End_Of_File (File) loop
declare
Next_Word : String := Ada.Text_IO.Get_Line (File);
Word : String := Get_Line (File);
begin
if Is_Ordered (Next_Word) then
if Next_Word'Length > Max_Length then
Max_Length := Next_Word'Length;
Word_Vectors.Clear (Ordered_Words);
Word_Vectors.Append (Ordered_Words, Next_Word);
elsif Next_Word'Length = Max_Length then
Word_Vectors.Append (Ordered_Words, Next_Word);
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;
Word_Vectors.Iterate (Ordered_Words, Print_Word'Access);
for Word of Ordered_Words loop
Put_Line (Word);
end loop;
Close (File);
end Ordered_Words;

View file

@ -0,0 +1,22 @@
'Ordered words - improved version
OPTION COLLAPSE TRUE
list$ = LOAD$("unixdict.txt")
FOR word$ IN list$ STEP NL$
SPLIT word$ BY 1 TO letter$ SIZE length
SORT letter$ SIZE length
JOIN letter$ BY "" TO term$ SIZE length
IF word$ = term$ THEN
IF length > MaxLen THEN
MaxLen = length
result$ = word$
ELIF length = MaxLen THEN
result$ = APPEND$(result$, 0, word$, NL$)
END IF
END IF
NEXT
PRINT result$

View file

@ -0,0 +1,30 @@
Public Sub Main()
Dim sDict As String = File.Load(User.Home &/ "unixdict.txt") 'Store the 'Dictionary'
Dim sOrdered As New String[] 'To store ordered words
Dim sHold As New String[] 'General store
Dim sTemp As String 'Temp variable
Dim siCount As Short 'Counter
For Each sTemp In Split(sDict, gb.NewLine) 'For each word in the Dictionary
For siCount = 1 To Len(sTemp) 'Loop for each letter in the word
sHold.Add(Mid(sTemp, siCount, 1)) 'Put each letter in sHold array
Next
sHold.Sort() 'Sort sHold (abbott = abboot, zoom = mooz)
If sTemp = sHold.Join("") Then sOrdered.Add(sTemp) 'If they are the same (abbott(OK) mooz(not OK)) then add to sOrdered
sHold.Clear 'Empty sHold
Next
siCount = 0 'Reset siCount
For Each sTemp In sOrdered 'For each of the Ordered words
If Len(sTemp) > siCount Then siCount = Len(sTemp) 'Count the length of the word and keep a record of the longest length
Next
For Each sTemp In sOrdered 'For each of the Ordered words
If Len(sTemp) = siCount Then sHold.Add(sTemp) 'If it is one of the longest add it to sHold
Next
sHold.Sort() 'Sort sHold
Print sHold.Join(gb.NewLine) 'Display the result
End

View file

@ -0,0 +1,27 @@
/*REXX list (the longest) ordered word(s) from a supplied dictionary. */
iFID= 'UNIXDICT.TXT'
w.=''
mL=0
Do j=1 While lines(iFID)\==0
x=linein(iFID)
w=length(x)
If w>=mL Then Do
Parse Upper Var x xU 1 z 2
Do k=2 To w
_=substr(xU, k, 1)
If \datatype(_, 'U') Then Iterate
If _<z Then Iterate j
z=_
End
mL=w
w.w=w.w x
End
End
nn=words(w.mL)
Say nn 'word's(nn) "found (of length" mL')'
Say ''
Do n=1 To nn
Say word(w.mL, n)
End
Exit
s: Return left('s',arg(1)>1)

View file

@ -1,3 +0,0 @@
from itertools import groupby
o = (w for w in map(str.strip, open("unixdict.txt")) if sorted(w)==list(w))
print list(next(groupby(sorted(o, key=len, reverse=True), key=len))[1])

View file

@ -0,0 +1,15 @@
words = #.split(#.readtext("unixdict.txt","ascii"),#.lf)
max = 0
> i, 1..#.size(words,1)
word = words[i]
wordb = #.array(word)
wordbc = #.size(wordb,1)
> j, 3..wordbc,2
<< wordb[j]<wordb[j-2]
<
>> j!>wordbc|wordbc<max
? wordbc>max, result = ""
? wordbc>max, max = wordbc
result += word+#.crlf
<
#.output(result)

View file

@ -0,0 +1,54 @@
BEGIN
BOOLEAN PROCEDURE ISORDERED(W); TEXT W;
BEGIN
BOOLEAN B;
B := TRUE;
W.SETPOS(1);
IF W.MORE THEN
BEGIN
CHARACTER CURR, LAST;
CURR := W.GETCHAR;
WHILE W.MORE AND B DO
BEGIN
LAST := CURR;
CURR := W.GETCHAR;
B := LAST <= CURR;
END;
END;
ISORDERED := B;
END;
REF (INFILE) INF;
INTEGER LONGEST;
TEXT W;
COMMENT FIND LONGEST LENGTH;
INF :- NEW INFILE("unixdict.txt");
INF.OPEN(BLANKS(132));
WHILE NOT INF.LASTITEM DO
BEGIN
W :- COPY(INF.IMAGE).STRIP;
IF ISORDERED(W) THEN
IF W.LENGTH > LONGEST THEN
LONGEST := W.LENGTH;
INF.INIMAGE;
END;
INF.CLOSE;
COMMENT OUTPUT ORDRERED WORDS OF LONGEST LENGTH;
INF :- NEW INFILE("unixdict.txt");
INF.OPEN(BLANKS(132));
WHILE NOT INF.LASTITEM DO
BEGIN
W :- COPY(INF.IMAGE).STRIP;
IF W.LENGTH = LONGEST AND THEN ISORDERED(W) THEN
BEGIN
OUTTEXT(W);
OUTIMAGE;
END;
INF.INIMAGE;
END;
INF.CLOSE;
END.

View file

@ -0,0 +1,11 @@
var words=L(), sz=0; // some state
fcn isLex(word){ word.reduce(fcn(p,c){ (p<=c) and c or T(Void.Stop,False) }) }
File("dict.txt").pump(Void,fcn(w){
w=w.strip(); // get rid of newline
if(isLex(w)){ n:=w.len();
if(n>sz){ words.clear(w); sz=n }
else if(n==sz) words.append(w)
}
})
println("Num words: %d, all size %d\n".fmt(words.len(),sz));
words.pump(Console.println);

View file

@ -0,0 +1,6 @@
fcn isLex(word){ word.reduce(fcn(p,c){ (p<=c) and c or T(Void.Stop,False) }) }
lwords:=File("dict.txt").readln(*).apply("strip").filter(isLex);
max:=lwords.reduce(fcn(n,w){ w.len()>n and w.len() or n },0);
lwords=lwords.filter(fcn(w,n){ w.len()==n },max);
println("Num words: %d, all size %d\n".fmt(lwords.len(),max));
words.pump(Console.println);