27
\$\begingroup\$

You may be aware of the famous old rhyme, "I before E, except after C". It is a rule taught to aid in the spelling of certain English words.

Quoting Wikipedia:

If one is not sure whether a word is spelled with the digraph ei or ie, the rhyme suggests that the correct order is ie unless the preceding letter is c, in which case it is ei.

It is well known that this rule is not always correct (e.g. weird, leisure, ancient). That is why you will be asked to write an algorithm which accurately determines the spelling of these words.

Task

The following wordlist (found here) consists of 2967 valid words, each of which contains either ei or ie as a substring.

The input is a single word \$ w \$ from the wordlist, but the ies and eis may be flipped (all occurrences of ie are replaced with ei, and vice versa). You are to output a boolean value indicating whether \$ w \$ was flipped. The values do not need to be True and False, so long as they are consistent. Your program must work correctly for all words, including their flipped counterparts (for a total of 5934 cases to consider). Here I've provided of a list of all possible test cases.

Note that you are not given this list as input. You must find a way to determine, for any word in the list, whether or not it is flipped but you cannot take the list itself as input.

Just to clarify, no word in the wordlist contains iei or eie as a substring, nor do a word and its flipped version both exist in the wordlist. As such, these ambiguous cases do not need to be considered. However, words such as friendlier or eighties which contain more than one occurrence of ei or ie do exist in the wordlist, in which case both occurrences are flipped (friendlier -> freindleir, eighties -> ieghteis).

Since this is , the shortest code in bytes wins.

As a side note, simply applying the "I before E, except after C" rule will be correct for 4954/5934 of the cases.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ ""I before E, except after C" rule will be correct for 4954/5934 of the cases"; But only test ie got 5036 / 5934 score?? \$\endgroup\$ – tsh Apr 23 at 3:38
  • \$\begingroup\$ Just created A jsFiddle for simple regex based test \$\endgroup\$ – tsh Apr 23 at 3:43
  • 3
    \$\begingroup\$ List of the 535 words with an exception (obtained by matching against the regex (?<!c)ei|cie) \$\endgroup\$ – hakr14 Apr 23 at 4:36
  • 1
    \$\begingroup\$ @hakr14 Note, that list contains 36 instances of eei, (e.g. agreeing) which when flipped will yield eie, which is explicitly excluded from the cases? \$\endgroup\$ – Darrel Hoffman Apr 23 at 17:02
  • 1
    \$\begingroup\$ @user Yep, good catch :). \$\endgroup\$ – dingledooper May 2 at 20:06
23
\$\begingroup\$

JavaScript (ES6), 338 bytes

A regex-based solution. This can probably be optimized some more.

Returns 0 (not flipped) or 1 (flipped).

w=>/dief|egh|etei|it?ei/.test(w)|/^(a?th0[rs]|d0st|r?0|h0r?[1s]|w0r)|b0[gt]|c0(l|t[es1]|v)|cl01|d0(f|n[1es]|ra|tie|ty)|0([aijop]|c1|[df]o|g[hln]|na?[fgor]|rlo|[rs]u|s[ahims]|tf|tm)|f0n?[at]|g0g|h0(fe|k|n|re)|ip01|k0n|n0t|no?th0|o0s|r0n1|rel01|rg0st|s0(l|ne|z)|t0n[es1]|u0n|un01|v0(l|n[1es])|yth0/.test(w.replace(/ei|ie/,0)+1)^/ei/.test(w)

Try it online!

(The total number of errors is reported in the Debug section of TIO, so you can collapse the Footer and Output sections if you just want to see that.)

How?

We first get rid of a few edge cases with the following regular expression:

/dief|egh|etei|it?ei/

which matches these flipped inputs (for which it's especially hard to tell that they are indeed flipped):

diefeid, diefeis, ieghteis, ieghteith, inhomogenieteis, pompiei, soceiteis,
wieghteir, wieghteist

Otherwise, we replace the first occurrence of either ei or ie in the input word with 0 and append a trailing 1:

w.replace(/ei|ie/, 0) + 1

We test whether the resulting string is matched by a large regular expression consisting of 23 patterns which are associated to words for which 0 must be ei.

Examples:

  • ath0stically1 is matched by ^(a?th0[rs]|d0st|r?0|h0r?[1s]|w0r)
  • rec0ved1 is matched by c0(l|t[1es]|v)
  • mad0ra1 is matched by d0(f|n[1ens]|ra|tie|ty)
  • ineffic0ncy1 is not matched by any expression
\$\endgroup\$
7
\$\begingroup\$

Python 3, 770 642 bytes

import zlib,base64
A=zlib.decompress(base64.b85decode(b'c$_7UYjVRd2!yY)S5qWp)5uZ=uru!IySP90V_|rGMa^-E&VNdB;H1S_2f|8290;)j7yV7J%d^Wq23sMpSzu$qo;^u@D9IyHvE~Y_aZ`-##Ee}q7bO~)P3UUc!*KBGJAe35sGn4Dg*q$hg)r7k+@W(Z-3BEF?F-tdS^~S|4-B0443B>&x}e|ad5xF>_ITn*?1VMqLoI4vi7nBIZ6>m-KsG}&MdPkJnYWr$LA@PyH5$<?F;L6Jv~;{Uj}p&oDC6}95|fNJ')).decode('utf-8').split()
g=lambda i:i[:2]=='ei'or i.replace('ei','')in'dst hr hrs hst rn thr thrs thst vn wr brun lorel nucl taip'.split()or any(w in i for w in A)
f=lambda i:'eei'in i or'eii'in i or(not('eie'in i or'iei'in i)and(i.index('ei')<i.index('ie')if'ei' in i and 'ie' in i else('ie'in i)^g(i.replace('ie','ei'))))

Try it online!

Ungolfed

l = 'eigh ceiv eing eism eign einv reins reim feit veil seiz neit einf odu eird istic rna igl tera seil eiss reini heists tm rpr isu eip heik dece ceil feint herein fy ido eish nceit ucl rlo olt noe eio dri caf trad rote icat hein iress heife mr ji oly mad iru ifo eia egr cys alb uein reic onot nthe ndee kein isin isan inon iger code cave beig weirs veins veine seine reine deity deists atheist'.split()

def f(i):
  if 'eei' in i or 'eii' in i: return True
  if 'eie' in i or 'iei' in i: return False
  if 'ie' in i and 'ei' in i: return i.index('ei')<i.index('ie')
  # there now can't be 'ei' and 'ie' in i
  if 'ei' in i:
    return goodei(i)
  return not goodei(j)

def goodei(i):
  if i[:2] == 'ei': return True
  if i in 'brunei lorelei nuclei taipei deist heir heirs heist rein their theirs theist vein weir'.split(): return True
  for w in l:
    if w in i: return True
  return False

The basic idea is that most of the time, if 'ie' is in the word, then it's a real word. So the code first gets rid of cases where there are both ei and ie in the word, and then checks if the word (with ie's replaced with ei's) is a real word.

The way it checks if a word with ei is a real word, is it uses a big list of strings that are present in only real words.

\$\endgroup\$
2
  • \$\begingroup\$ Wow, very cool! \$\endgroup\$ – knosmos Apr 23 at 19:47
  • \$\begingroup\$ 614 bytes (I had to remove testcases and the compressed string to fit the link in a comment.) \$\endgroup\$ – ovs Apr 24 at 12:05
6
\$\begingroup\$

Python 3, 12,707 12,219 bytes

(Thanks to ovs and caird coinheringaahing)

import zlib,base64
print(input()in str(zlib.decompress(base64.a85decode(b'G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Zc_sPUu_$aq,]Ro-(6@mpI\'Nk4f>6BR)A\\;Y+BWIu>Z@pSg$s.q#!`?>:"[l+*?bplD(Cj]j(FTDePa0c[h?J?J_oBlB%#=8(TPGC<Z\\R"88jj!_0pCqe>:.tL>sAL:GK9"d4?SQ>?3B$sf279`?A;K==EUfW1p77?l\'TPmXIGCV%os%2qP*=;6M]*:*AcP9L3]<eYQ-FbM2deiZCe#eY]EX4QiA21JeCk,Vl9g[`H$R<\\5r0EN[k$]+m_8K#(;?Nr(j*R*)5>Zm!)6K.O)&FXtP3WLXZ\\8Z#K4r0"OBa_Pc#5_#,UZ3emN&oh,!&0Wtl87+;<R_67\'l@:pO\'0#,gM5ASq&$)hsqUOaW25ri7Aq@_UKhJeIB`X_/+=kFNaDD0\'UqX+<2`8a#pGF;p$8\\mdgl-"kpiU?(4X>AT_U&i*=J8OlS]Xq(H>P21;<VIe\\#EbLW?MQe_N6CP@QE[7"oX>CSYjcp:7=Ug#9jN.B9I`er^:Dc;T[;p"`_Aj>hEUZ#K@tSgb+b$5GsV1o^]!Y^Mn7fQGJ(iK+m<QkQs&/p\\<V2;RqZ]oFZ4dGn8juc?0\\!?Hm)o-!P9Qg0X>EleK"HLN#hWqrDlD7X5@&:;I>R(\'8#\\`H)`VE8>KD:1?5WNN[L,QHYDKKi>4Khp;\'\\,`\\4"a\\kt\\d!89R2VOme\\4,[]<0U9A#XEejmIIe<=3sMK>XGLkc<I+2;b\'SgTjT$j16pT$C.i9s-^#Q9&GNM[6!]cIr,lhX.19:ur>cdigjUUL;W0\\J;m$m]8J.Qe;p?egMoI1lcW=NdEO4YORd)S")Q+d)jW"8hSIj_2g^Nm<37m3*(rssg.bO,'))).split('\\r\\n'))

Searches for the input in a compressed string. Definitely could use some improvement.

\$\endgroup\$
4
  • \$\begingroup\$ If you're willing to switch to Python 3 the base64 module has the functions a85encode and a85decode which should encode the compressed string a little shorter. \$\endgroup\$ – ovs Apr 23 at 13:56
  • \$\begingroup\$ Ooh, will definitely take a look at that. Thanks! \$\endgroup\$ – knosmos Apr 23 at 13:58
  • \$\begingroup\$ You can remove the space after input() and you can get rid of a entirely by moving the compressed string into the base64.a85decode(...) \$\endgroup\$ – caird coinheringaahing Apr 23 at 14:09
  • \$\begingroup\$ You are correct, thanks! \$\endgroup\$ – knosmos Apr 23 at 14:12
4
\$\begingroup\$

Jelly, 439 418 bytes

“£ɦ^“PȮ’ḶḤ‘2¦×3‘FḃØ⁵ịØJ⁾“»jⱮVŒl;“þðxiṄḂÞẹṅŻÞÑɗðṁṙGm³L⁽ẉṇ/yƥɠỵỊ£nżsCµ®ỵ⁾ọȧƇẏƑtNgŻỊ⁺ẈɓỤɼʂrƓėɓẓøb6^ḍḃ"vṂỴ÷ƭVṖẇƥƑ¤æⱮẆẓ\6SNḌ|¢YỤṘ⁽r&AµwƓTṃṭṚHẇ¶(ȮçðṁÑLẉṃı-ÆẸbCṄ¢ɲʂ§ȦS³ịẆu⁽ạİ*ṁ©ß¬ḌZɗẒ¦ṫṃÑ+ṬẠ½ṠȷḂðȧç⁾xḥẹ)ẒɗJĿḍʋƲṚɠ_yỴ\9j6ḥḍƘḥÇ2Hƙṃ⁸Ụ°ṭ¹Ḍṭñ9Ẏ²ẈḍyẇƇ[ṃİḅ⁾µỌø§}UḳỤḷCs4ṗȤ7ȦĠƲżḤ,:ṡÑjb`AOẓḷỴƲY½;ẹ5£ẈṂQ:Ṁ¹ḋ4q+£Ø³ĖĊȷ#4&¶C⁾ÞẒƲṾı0"ɲFɠðƁḊḅ8yṪÐnŒN§i²ȧ2ẆƈUỌỤḟ¥$²Ɓj³ḥ-ƤṢṆƑġ⁽ṫƥG_BẈṇØ_¬ñẹ)¤rŀḍƑʂỴḞ`⁷¹ḤdƘbọzi³©E»Ḳ¤ḟ“ßGW€)Ɗ6ɱ8ʂṖṗ¥ṙ®×ɓƲ⁹»Ḳ¤;;€”s$$e@

Try it online!

A monadic link taking a string as input and outputting 0 for incorrect and 1 for correct.

Takes advantage of the dictionary in Jelly, but has to add some additional non-dictionary words as remove a few that are in the dictionary.

Slow when used repeatedly because the dictionary is generated each time. Now generates the dictionary purely using Jelly (rather than calling Python code directly)

\$\endgroup\$
3
\$\begingroup\$

Python 3, 3384 bytes

import re,zlib,base64
G,H=["".join(map(chr,zlib.decompress(base64.a85decode(x)))).split()for x in[b'Gar?3CQa?!%"PP@eS)db*<_:.:\\C<.o7j7C6bYeu*^[Y=?7CpeN&,$aRJ0:HPcnf*]g<auqG$d6NX]:OM9:<gI?X".<gEtbcgB8TRe!nBg,QG?+FR.jgR`H-nMCOR(e>rR["sGCjjaHAkSMe#S]7`d73cUEKGOh0hl2pKYh+5uL\\N-U_#nCoV!Dn]i(Q,eK,+?HhOW>JC)p>Tijak_Zn+`5f=$0;nGHbL_f=\'$`a:$T7_OX<Shd8l!7b%tP0%Ca%EsK[K.D6*G9+4ok-($\'"@GfPTLm1qq/`Ng/`he.\\W#pb1=;,UbtsJ!mMu"_#,8u-#u9"8:V\\Qg+BRUsi\\I@q0M]HZPpiFCGJ\\8FW6X:[`_+F4d&@J>(lq.H\\=*5;,hgaR[k]T2]1Rp\\a-,#+!D(]`V6ngIXVEo[b1EAp/oa9W01K?jh[PutO\\,u7I(Lf<eUumH](R80*0g:F0SJgfbLoJ&),suqDE[@b9]9JK?C2Z%JR0O&\'b_\'a*O\'`T)R$D+YcR5#ajGD90U[SdCR9ZQE=$.(<.c9J5+dXM$m$7O%JL1tbd/&L#7o27Y$(YOfMf0AXVu#dP^2D4>nb/VI8O3Yk5(bO->Cn[lmE@8qBRa?Q_/fgN=GT)VcCR>K7*]gh^!b:\\&rB7,?"A4TbEKfNI4D$a3Q$4Uj;90/;t%J)prQ8.\'`JrngCEmQ#_Kc/EpPL3QC\'<)<M94XZ!jQ-Ba-7YZ5!i/mn#1PKno<nW*lQV=ej4=-#8deA%3T3b^#8itGakSRs9Zh\\oft&1CD_8!^sl]aZE@0l67;)</Z*:T!E1618bG(=\'--qUSQ9&=qU<qRoP=0o!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QsTIN+7Soa,o*Id2sK9J65&PsLF=@##-D]);C-&&o"^VE0"E^<.U*K&J!L]t980_G&tpej$2_PLJ@DniaRN`P$JIE>"!C^g-s0a3.9\\ns&.!O$"AY7fQ?nl35I5BS"f:[QW!`iJ)Wj\\UaWs4Z"j?.I?X`//sE5-iYYDnn#<_0\\IXpm?Lf+*)mPq<B9b0;S""IZ3P0C(5#"$Dfh84Y:oa.p;bc5EUOFh#\\q71Dt=\\<qq]h)XF.9g1iVX2s<h*Za("A-g@ZZlNT#b/F\\.MQl9c']]
f=lambda s:s in G or(s not in H and re.search("seil|ie(?!ng|sm)|eing|eism",s))

Try it online!

You could probably save more bytes with a smarter regex. Basically, just a tradeoff between longer regex and shorter encoded strings.

G is the list of true cases, H is a list of false cases. s in G or makes it so if it's a true case, it gets marked as such. s not in H and makes it so if it's a false case, it gets marked as such. If neither is true, then it is checked with the regex /seil|ie(?!ng|sm)|eing|eism/. Finding a longer regex to match even just like 3-4 more words is certainly worth it, I just didn't want to spend too much time.

\$\endgroup\$
1
  • \$\begingroup\$ zlib.decompress(base64.a85decode(x)).decode().split() saves a few bytes. And you have quite a few extra backslashes in your base-85 string, you can remove them with this script: tio.run/… \$\endgroup\$ – ovs Apr 24 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.