RosettaCodeData/Task/I-before-E-except-after-C/SETL/i-before-e-except-after-c.setl
2023-12-16 21:33:55 -08:00

34 lines
1,000 B
Text

program i_before_e_except_after_c;
init cie := 0, xie := 0, cei := 0, xei := 0;
dict := open("unixdict.txt", "r");
loop doing word := getline(dict); while word /= om do
classify(word);
end loop;
close(dict);
p :=
plausible("I before E when not preceded by C", xie, cie) and
plausible("E before I when preceded by C", cei, xei);
print;
print("I before E, except after C:" + (if p then "" else " not" end)
+ " plausible.");
proc classify(word);
if "ie" in word then
if "cie" in word then cie +:= 1;
else xie +:= 1;
end if;
elseif "ei" in word then
if "cei" in word then cei +:= 1;
else xei +:= 1;
end if;
end if;
end proc;
proc plausible(clause, feature, opposite);
p := 2 * feature > opposite;
print(clause + ":" + (if p then "" else " not" end) + " plausible.");
return p;
end proc;
end program;