Jump to content

Words from neighbour ones: Difference between revisions

Added XPL0 example.
(Added 11l)
(Added XPL0 example.)
Line 1,479:
23: transport
24: transpose
</pre>
 
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
 
func StrCmp(A, B); \Compare string A to B
char A, B; \Returns: >0 if A>B, =0 if A=B, and <0 if A<B
int I;
[for I:= 0 to -1>>1 do
[if A(I) # B(I) then return A(I) - B(I);
if A(I) = 0 then return 0;
];
]; \StrCmp
 
func LookUp(Word); \Return 'true' if Word is in Dict
char Word;
int Lo, Hi, I, Cmp;
[Lo:= 0; Hi:= DictSize-1;
loop [I:= (Lo+Hi) / 2; \binary search
Cmp:= StrCmp(Word, Dict(I));
if Cmp < 0 then Hi:= I-1 else Lo:= I+1;
if Cmp = 0 then return true;
if Lo > Hi then return false;
];
]; \LookUp
 
int DI, I, Ch, Count;
char Word, Neigh(10), Last(10);
def LF=$0A, CR=$0D, EOF=$1A;
 
[FSet(FOpen("unixdict.txt", 0), ^I); \load dictionary
OpenI(3); \assume alphabetical order and all lowercase
DI:= 0;
repeat Dict(DI):= Reserve(0); \get pointer to memory used to store Word
Word:= Dict(DI);
I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
if I >= 9 then \ignore words less than 9 characters
[Word(I):= 0; \terminate Word string
I:= Reserve(I+1); \reserve memory used for Word
DI:= DI+1; \next dictionary entry
];
until Ch = EOF;
DictSize:= DI;
 
DI:= 0; Count:= 0; Last(0):= 0;
repeat for I:= 0 to 9-1 do \build Neigh word using letters from
[Word:= Dict(DI+I); \ following words
Neigh(I):= Word(I);
];
Neigh(9):= 0; \terminate string
if LookUp(Neigh) then \if it's a word and not already listed
if StrCmp(Neigh, Last) # 0 then
[CopyMem(Last, Neigh, 10);
Count:= Count+1;
Text(0, Neigh);
if rem(Count/8) = 0 then CrLf(0) else ChOut(0, ^ );
];
DI:= DI+1; \next word in dictionary
until DI >= DictSize-9;
CrLf(0);
]</lang>
 
{{out}}
<pre>
applicate architect astronomy christine christoph committee composite constrict
construct different extensive greenwood implement improvise intercept interpret
interrupt philosoph prescript receptive telephone transcend transport transpose
</pre>
 
772

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.