RosettaCodeData/Task/I-before-E-except-after-C/Phix/i-before-e-except-after-c.phix
2019-09-12 10:33:56 -07:00

50 lines
1.6 KiB
Text

--
-- demo\rosetta\IbeforeE.exw
-- =========================
--
procedure fatal(string msg)
printf(1,"unixdict.txt %s. download it from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt\n",{msg})
if getc(0) then end if
abort(1)
end procedure
procedure show_plausibility(string msg, integer w, wo)
printf(1, "%s (pro: %3d, anti: %3d) is%s plausible\n",{msg,w,wo," not"[1..-(w<2*wo)]})
end procedure
integer fn = open(join_path({"..","unixdict.txt"}),"r")
if fn=-1 then
fn = open("unixdict.txt","r")
if fn=-1 then fatal("not found") end if
end if
string text = get_text(fn)
close(fn)
-- Note: my unixdict.txt begins with "10th" and ends
-- with "zygote", so boundary checks can be skipped.
integer {cei,xei,cie,xie} @= 0
for i=1 to length(text) do
if text[i]='i' then
if text[i-1]='e' then
if text[i-2]='c' then
cei += 1
else
xei += 1
end if
end if
-- (not elsif here; "eie" occurs twice)
if text[i+1]='e' then
if text[i-1]='c' then
cie += 1
else
xie += 1
end if
end if
end if
end for
printf(1,"occurances: cie:%d, xie:%d, cei:%d, xei:%d\n", {cie,xie,cei,xei})
show_plausibility("i before e except after c", xie, cie)
show_plausibility("e before i except after c", xei, cei)
show_plausibility("i before e when after c", cie, cei)
show_plausibility("e before i when after c", cei, cie)
show_plausibility("i before e in general", xie + cie, xei + cei)
show_plausibility("e before i in general", xei + cei, xie + cie)