I before E except after C: Difference between revisions

Content added Content deleted
m (→‎Raku: Stretch Goal: Latest requires explicit coercion to numeric)
Line 1,964: Line 1,964:
I before E when not preceded by C: is plausible
I before E when not preceded by C: is plausible
E before I when preceded by C: is not plausible</pre>
E before I when preceded by C: is not plausible</pre>

=={{header|Nim}}==
<lang Nim>import httpclient, strutils, strformat

const
Rule1 = "\"I before E when not preceded by C\""
Rule2 = "\"E before I when preceded by C\""
Phrase = "\"I before E except after C\""
PlausibilityText: array[bool, string] = ["not plausible", "plausible"]


proc plausibility(rule: string; count1, count2: int): bool =
## Compute, display and return plausibility.
result = count1 > 2 * count2
stdout.write &"The rule {rule} is {PlausibilityText[result]}: "
echo &"there were {count1} examples and {count2} counter-examples."


let client = newHttpClient()

var nie, cie, nei, cei = 0
for word in client.getContent("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").split():
if word.contains("ie"):
if word.contains("cie"):
inc cie
else:
inc nie
if word.contains("ei"):
if word.contains("cei"):
inc cei
else:
inc nei

let p1 = plausibility(Rule1, nie, nei)
let p2 = plausibility(Rule2, cei, cie)
echo &"So the phrase {Phrase} is {PlausibilityText[p1 and p2]}."</lang>

{{out}}
<pre>The rule "I before E when not preceded by C" is plausible: there were 465 examples and 213 counter-examples.
The rule "E before I when preceded by C" is not plausible: there were 13 examples and 24 counter-examples.
So the phrase "I before E except after C" is not plausible.</pre>


=={{header|Objeck}}==
=={{header|Objeck}}==