RosettaCodeData/Task/I-before-E-except-after-C/XPL0/i-before-e-except-after-c.xpl0
2024-10-16 18:07:41 -07:00

32 lines
996 B
Text

include xpllib; \for StrFind and Print
int I, Ch, CI, XI, CE, XE;
char Word(100); \(longest word in unixdict.txt is 22 chars)
[FSet(FOpen("unixdict.txt", 0), ^I); \open dictionary and set it to device 3
OpenI(3);
repeat I:= 0;
loop [Ch:= ChIn(3);
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
Word(I):= 0; \terminate string
if StrFind(Word, "ie") then
if StrFind(Word, "cie") then CI:= CI+1 else XI:= XI+1;
if StrFind(Word, "ei") then
if StrFind(Word, "cei") then CE:= CE+1 else XE:= XE+1;
until Ch = EOF;
Print("CIE: %d\n", CI);
Print("xIE: %d\n", XI);
Print("CEI: %d\n", CE);
Print("xEI: %d\n\n", XE);
Print("I before E when not preceded by C: ");
if 2*XI < CI then Print("not ");
Print("plausible.\n");
Print("E before I when preceded by C: ");
if 2*CI < XE then Print("not ");
Print("plausible.\n");
]