Changeable words: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: use GT_LF_STRIPPED |
Added XPL0 example. |
||
Line 782:
51: upperclassman -> upperclassmen
52: upperclassmen -> upperclassman
</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 I, J, L, DI, Ch, Count;
char Word, ChgWord(25); \longest word in unixdict.txt is 22 chars
def Tab=$09, LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I); \load dictionary
OpenI(3); \assume alphabetical order and all lowercase
DI:= 0; \ignore non-alpha characters: 0..9, ' and &
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;
];
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; \print out all changeable words
repeat Word:= Dict(DI); \assume all lowercase letters
I:= 0; J:= 0;
loop [Ch:= Word(I);
if Ch = 0 then quit;
ChgWord(I):= Ch;
I:= I+1;
];
ChgWord(I):= 0;
if I >= 12 then \Word must have at least 12 chars
[for J:= 0 to I-1 do \for all letter positions in Word
[for L:= ^a to ^z do \for all letters
if L # Word(J) then
[ChgWord(J):= L;
if LookUp(ChgWord) then
[Count:= Count+1;
IntOut(0, Count); ChOut(0, Tab);
Text(0, Word); ChOut(0, Tab);
Text(0, ChgWord);
CrLf(0);
];
ChgWord(J):= Word(J); \undo letter change
];
];
];
DI:= DI+1;
until DI >= DictSize;
]</lang>
{{out}}
<pre>
1 aristotelean aristotelian
2 aristotelian aristotelean
3 claustrophobia claustrophobic
4 claustrophobic claustrophobia
5 committeeman committeemen
6 committeemen committeeman
7 committeewoman committeewomen
8 committeewomen committeewoman
9 complementary complimentary
10 complimentary complementary
11 confirmation conformation
12 conformation confirmation
13 congresswoman congresswomen
14 congresswomen congresswoman
15 councilwoman councilwomen
16 councilwomen councilwoman
17 craftsperson draftsperson
18 draftsperson craftsperson
19 eavesdropped eavesdropper
20 eavesdropper eavesdropped
21 frontiersman frontiersmen
22 frontiersmen frontiersman
23 handicraftsman handicraftsmen
24 handicraftsmen handicraftsman
25 incommutable incomputable
26 incomputable incommutable
27 installation instillation
28 instillation installation
29 kaleidescope kaleidoscope
30 kaleidoscope kaleidescope
31 neuroanatomy neuroanotomy
32 neuroanotomy neuroanatomy
33 newspaperman newspapermen
34 newspapermen newspaperman
35 nonagenarian nonogenarian
36 nonogenarian nonagenarian
37 onomatopoeia onomatopoeic
38 onomatopoeic onomatopoeia
39 philanthrope philanthropy
40 philanthropy philanthrope
41 prescription proscription
42 proscription prescription
43 schizophrenia schizophrenic
44 schizophrenic schizophrenia
45 shakespearean shakespearian
46 shakespearian shakespearean
47 spectroscope spectroscopy
48 spectroscopy spectroscope
49 underclassman underclassmen
50 underclassmen underclassman
51 upperclassman upperclassmen
52 upperclassmen upperclassman
</pre>
|