I before E except after C: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 36: Line 36:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V PLAUSIBILITY_RATIO = 2
<syntaxhighlight lang="11l">V PLAUSIBILITY_RATIO = 2


F plausibility_check(comment, x, y)
F plausibility_check(comment, x, y)
Line 66: Line 66:
print(‘Checking plausibility of "I before E except after C":’)
print(‘Checking plausibility of "I before E except after C":’)
V (cei, cie, not_c_ie, not_c_ei) = simple_stats()
V (cei, cie, not_c_ie, not_c_ei) = simple_stats()
print_result(cei, cie, not_c_ie, not_c_ei)</lang>
print_result(cei, cie, not_c_ie, not_c_ei)</syntaxhighlight>


{{out}}
{{out}}
Line 88: Line 88:
(Indeed, <code>unixdict.txt</code> is 206k.)
(Indeed, <code>unixdict.txt</code> is 206k.)


<lang 8080asm> ;;; I before E, except after C
<syntaxhighlight lang="8080asm"> ;;; I before E, except after C
fcb1: equ 5Ch ; FCB 1 (populated by file on command line)
fcb1: equ 5Ch ; FCB 1 (populated by file on command line)
dma: equ 80h ; Standard DMA location
dma: equ 80h ; Standard DMA location
Line 294: Line 294:
cei: dw 0 ; E before I when preceded by C
cei: dw 0 ; E before I when preceded by C
xei: dw 0 ; E before I when not preceded by C
xei: dw 0 ; E before I when not preceded by C
curwrd: equ $ ; Current word stored here</lang>
curwrd: equ $ ; Current word stored here</syntaxhighlight>


{{out}}
{{out}}
Line 308: Line 308:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} Uses non-standard procedure to lower available in Algol 68G.
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} Uses non-standard procedure to lower available in Algol 68G.
<lang algol68># tests the plausibility of "i before e except after c" using unixdict.txt #
<syntaxhighlight lang="algol68"># tests the plausibility of "i before e except after c" using unixdict.txt #


# implements the plausibility test specified by the task #
# implements the plausibility test specified by the task #
Line 387: Line 387:
show plausibility( "i before e in general", xie + cie, xei + cei );
show plausibility( "i before e in general", xie + cie, xei + cei );
show plausibility( "e before i in general", xei + cei, xie + cie )
show plausibility( "e before i in general", xei + cei, xie + cie )
FI</lang>
FI</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 407: Line 407:
===Vanilla===
===Vanilla===


<lang applescript>on ibeeac()
<syntaxhighlight lang="applescript">on ibeeac()
script o
script o
property wordList : words of (read file ((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as «class utf8»)
property wordList : words of (read file ((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as «class utf8»)
Line 447: Line 447:
end ibeeac
end ibeeac


ibeeac()</lang>
ibeeac()</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>{|"I before E not after C" is plausible|:true, |"E before I after C" is plausible|:false, |Both are plausible|:false}</lang>
<syntaxhighlight lang="applescript">{|"I before E not after C" is plausible|:true, |"E before I after C" is plausible|:false, |Both are plausible|:false}</syntaxhighlight>


===AppleScriptObjC===
===AppleScriptObjC===


<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use framework "Foundation"
use scripting additions
use scripting additions
Line 483: Line 483:
end ibeeac
end ibeeac


ibeeac()</lang>
ibeeac()</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>{|"I before E not after C" is plausible|:true, |"E before I after C" is plausible|:false, |Both are plausible|:false}</lang>
<syntaxhighlight lang="applescript">{|"I before E not after C" is plausible|:true, |"E before I after C" is plausible|:false, |Both are plausible|:false}</syntaxhighlight>




===Functional===
===Functional===
<lang applescript>use AppleScript version "2.4"
<syntaxhighlight lang="applescript">use AppleScript version "2.4"
use framework "Foundation"
use framework "Foundation"
use scripting additions
use scripting additions
Line 736: Line 736:
end tell
end tell
end if
end if
end zipWith</lang>
end zipWith</syntaxhighlight>
{{Out}}
{{Out}}
<pre>[^c]ie > [^c]ei -> 466 / 217 = 2.15 :: plausible
<pre>[^c]ie > [^c]ei -> 466 / 217 = 2.15 :: plausible
Line 742: Line 742:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>WordList := URL_ToVar("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
<syntaxhighlight lang="autohotkey">WordList := URL_ToVar("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
WordList := RegExReplace(WordList, "i)cie", "", cieN)
WordList := RegExReplace(WordList, "i)cie", "", cieN)
WordList := RegExReplace(WordList, "i)cei", "", ceiN)
WordList := RegExReplace(WordList, "i)cei", "", ceiN)
Line 763: Line 763:
WebRequest.Send()
WebRequest.Send()
return, WebRequest.ResponseText
return, WebRequest.ResponseText
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>"I before E when not preceded by C" is plausible.
<pre>"I before E when not preceded by C" is plausible.
Line 774: Line 774:


=={{header|AWK}}==
=={{header|AWK}}==
<lang awk>#!/usr/bin/awk -f
<syntaxhighlight lang="awk">#!/usr/bin/awk -f


/.ei/ {nei+=cnt($3)}
/.ei/ {nei+=cnt($3)}
Line 799: Line 799:
print "E before I when preceded by C: is"v2" plausible";
print "E before I when preceded by C: is"v2" plausible";
print "Overall rule is"v" plausible";
print "Overall rule is"v" plausible";
}</lang>
}</syntaxhighlight>


Usage:
Usage:
Line 821: Line 821:
=={{header|Batch File}}==
=={{header|Batch File}}==
Download first the text file, then put it on the same directory with this sample code:
Download first the text file, then put it on the same directory with this sample code:
<lang dos>::I before E except after C task from Rosetta Code Wiki
<syntaxhighlight lang="dos">::I before E except after C task from Rosetta Code Wiki
::Batch File Implementation
::Batch File Implementation


Line 857: Line 857:


pause
pause
exit /b 0</lang>
exit /b 0</syntaxhighlight>
{{Out}}
{{Out}}
<pre>Plausibility of "I before E when not preceded by C": TRUE (465 VS 213)
<pre>Plausibility of "I before E when not preceded by C": TRUE (465 VS 213)
Line 867: Line 867:
Each word is counted once if word has at least one occurrence of test string (word with 2 or more occurrences only counts once).
Each word is counted once if word has at least one occurrence of test string (word with 2 or more occurrences only counts once).
The same word may count toward different categories.
The same word may count toward different categories.
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal enableDelayedExpansion
setlocal enableDelayedExpansion
for /f %%A in ('findstr /i "^ie [^c]ie" unixdict.txt ^| find /c /v ""') do set Atrue=%%A
for /f %%A in ('findstr /i "^ie [^c]ie" unixdict.txt ^| find /c /v ""') do set Atrue=%%A
Line 877: Line 877:
echo I before E when not preceded by C: True=%Atrue% False=%Afalse% : !Answer%Aresult%!
echo I before E when not preceded by C: True=%Atrue% False=%Afalse% : !Answer%Aresult%!
echo E before I when preceded by C: True=%Btrue% False=%Bfalse% : !Answer%Bresult%!
echo E before I when preceded by C: True=%Btrue% False=%Bfalse% : !Answer%Bresult%!
echo I before E, except after C : !Answer%Result%!</lang>
echo I before E, except after C : !Answer%Result%!</syntaxhighlight>
{{Out}}
{{Out}}
<pre>I before E when not preceded by C: True=465 False=213 : Plausible
<pre>I before E when not preceded by C: True=465 False=213 : Plausible
Line 886: Line 886:
Each word frequency is included once if word has at least one occurrence of test string (word with 2 or more occurrences only counts once).
Each word frequency is included once if word has at least one occurrence of test string (word with 2 or more occurrences only counts once).
The same word frequency may count toward different categories.
The same word frequency may count toward different categories.
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal enableDelayedExpansion
setlocal enableDelayedExpansion
set /a Atrue=Afalse=Btrue=Bfalse=0
set /a Atrue=Afalse=Btrue=Bfalse=0
Line 897: Line 897:
echo I before E when not preceded by C: True=%Atrue% False=%Afalse% : !Answer%Aresult%!
echo I before E when not preceded by C: True=%Atrue% False=%Afalse% : !Answer%Aresult%!
echo E before I when preceded by C: True=%Btrue% False=%Bfalse% : !Answer%Bresult%!
echo E before I when preceded by C: True=%Btrue% False=%Bfalse% : !Answer%Bresult%!
echo I before E, except after C : !Answer%Result%!</lang>
echo I before E, except after C : !Answer%Result%!</syntaxhighlight>
{{Out}}
{{Out}}
<pre>I before E when not preceded by C: True=8192 False=4826 : Implausible
<pre>I before E when not preceded by C: True=8192 False=4826 : Implausible
Line 904: Line 904:


=={{header|BASIC}}==
=={{header|BASIC}}==
<lang basic>10 DEFINT A-Z
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 OPEN "I",1,"UNIXDICT.TXT": GOTO 60
20 OPEN "I",1,"UNIXDICT.TXT": GOTO 60
30 LINE INPUT #1,W$
30 LINE INPUT #1,W$
Line 920: Line 920:
150 PRINT "E before I when preceded by C: ";
150 PRINT "E before I when preceded by C: ";
160 IF 2*CE <= XE THEN PRINT "not ";
160 IF 2*CE <= XE THEN PRINT "not ";
170 PRINT "plausible."</lang>
170 PRINT "plausible."</syntaxhighlight>
{{out}}
{{out}}
<pre>CIE: 24
<pre>CIE: 24
Line 933: Line 933:
=={{header|BASIC256}}==
=={{header|BASIC256}}==
{{trans|BASIC}}
{{trans|BASIC}}
<lang freebasic>CI = 0 : XI = 0 : CE = 0 : XE = 0
<syntaxhighlight lang="freebasic">CI = 0 : XI = 0 : CE = 0 : XE = 0
open 1, "unixdict.txt"
open 1, "unixdict.txt"


Line 958: Line 958:
if 2 * CE <= XE then print "not ";
if 2 * CE <= XE then print "not ";
print "plausible."
print "plausible."
end</lang>
end</syntaxhighlight>


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"


// Read word from selected input
// Read word from selected input
Line 1,014: Line 1,014:
writef("E before I when preceded by C: %Splausible.*N",
writef("E before I when preceded by C: %Splausible.*N",
2*ncei > nxei -> "", "not ")
2*ncei > nxei -> "", "not ")
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre>CIE: 24
<pre>CIE: 24
Line 1,028: Line 1,028:
This may in turn motivate me to provide a second J solution as a single pass FSM.
This may in turn motivate me to provide a second J solution as a single pass FSM.
Please find the program output hidden at the top of the source as part of the build and example run.
Please find the program output hidden at the top of the source as part of the build and example run.
<syntaxhighlight lang="c">
<lang c>
%{
%{
/*
/*
Line 1,061: Line 1,061:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{trans|Java}}
{{trans|Java}}
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.IO;
Line 1,119: Line 1,119:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Plausible count: 384
<pre>Plausible count: 384
Line 1,132: Line 1,132:
:* (Test used 4.4, so only a limited number of C++11 features were used.)
:* (Test used 4.4, so only a limited number of C++11 features were used.)


<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <fstream>
#include <fstream>
#include <string>
#include <string>
Line 1,233: Line 1,233:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,248: Line 1,248:
The output here was generated with the files as of 21st June 2016.
The output here was generated with the files as of 21st June 2016.


<lang clojure>
<syntaxhighlight lang="clojure">
(ns i-before-e.core
(ns i-before-e.core
(:require [clojure.string :as s])
(:require [clojure.string :as s])
Line 1,302: Line 1,302:
(with-open [rdr (clojure.java.io/reader "http://ucrel.lancs.ac.uk/bncfreq/lists/1_2_all_freq.txt")]
(with-open [rdr (clojure.java.io/reader "http://ucrel.lancs.ac.uk/bncfreq/lists/1_2_all_freq.txt")]
(i-before-e-except-after-c-plausible? "Word frequencies (stretch goal)" (map format-freq-line (drop 1 (line-seq rdr))))))
(i-before-e-except-after-c-plausible? "Word frequencies (stretch goal)" (map format-freq-line (drop 1 (line-seq rdr))))))
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,322: Line 1,322:


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>report = cluster is new, classify, results
<syntaxhighlight lang="clu">report = cluster is new, classify, results
rep = record[cie, xie, cei, xei, words: int]
rep = record[cie, xie, cei, xei, words: int]
Line 1,394: Line 1,394:
stream$close(fstream)
stream$close(fstream)
stream$puts(po, report$results(r))
stream$puts(po, report$results(r))
end start_up </lang>
end start_up </syntaxhighlight>
{{out}}
{{out}}
<pre>Amount of words: 25104
<pre>Amount of words: 25104
Line 1,412: Line 1,412:
Now we can do the task:
Now we can do the task:


<lang coco>ie-npc = ei-npc = ie-pc = ei-pc = 0
<syntaxhighlight lang="coco">ie-npc = ei-npc = ie-pc = ei-pc = 0
for word of dict.toLowerCase!.match /\S+/g
for word of dict.toLowerCase!.match /\S+/g
++ie-npc if /(^|[^c])ie/.test word
++ie-npc if /(^|[^c])ie/.test word
Line 1,424: Line 1,424:
console.log '(1) is%s plausible.', if p1 then '' else ' not'
console.log '(1) is%s plausible.', if p1 then '' else ' not'
console.log '(2) is%s plausible.', if p2 then '' else ' not'
console.log '(2) is%s plausible.', if p2 then '' else ' not'
console.log 'The whole phrase is%s plausible.', if p1 and p2 then '' else ' not'</lang>
console.log 'The whole phrase is%s plausible.', if p1 and p2 then '' else ' not'</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==


<lang lisp>
<syntaxhighlight lang="lisp">
(defun test-rule (rule-name examples counter-examples)
(defun test-rule (rule-name examples counter-examples)
(let ((plausible (if (> examples (* 2 counter-examples)) 'plausible 'not-plausible)))
(let ((plausible (if (> examples (* 2 counter-examples)) 'plausible 'not-plausible)))
Line 1,463: Line 1,463:
(plausibility "Dictionary" #p"unixdict.txt" #'parse-dict)
(plausibility "Dictionary" #p"unixdict.txt" #'parse-dict)
(plausibility "Word frequencies (stretch goal)" #p"1_2_all_freq.txt" #'parse-freq)
(plausibility "Word frequencies (stretch goal)" #p"1_2_all_freq.txt" #'parse-freq)
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,481: Line 1,481:
=={{header|D}}==
=={{header|D}}==
The extra work has not been attempted
The extra work has not been attempted
<lang D>import std.file;
<syntaxhighlight lang="d">import std.file;
import std.stdio;
import std.stdio;


Line 1,604: Line 1,604:
}
}
return cnt;
return cnt;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,616: Line 1,616:
{{libheader| System.IOUtils}}
{{libheader| System.IOUtils}}
{{Trans|C sharp}}
{{Trans|C sharp}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program I_before_E_except_after_C;
program I_before_E_except_after_C;


Line 1,676: Line 1,676:
Writeln('Rule is not plausible.');
Writeln('Rule is not plausible.');


end.</lang>
end.</syntaxhighlight>


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>\util.g
<syntaxhighlight lang="draco">\util.g


/* variables to hold totals for each possibility */
/* variables to hold totals for each possibility */
Line 1,737: Line 1,737:
if p then "" else "not " fi,
if p then "" else "not " fi,
"plausible.")
"plausible.")
corp</lang>
corp</syntaxhighlight>
{{out}}
{{out}}
<pre>CIE: 24
<pre>CIE: 24
Line 1,749: Line 1,749:
=={{header|Elixir}}==
=={{header|Elixir}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang elixir>defmodule RC do
<syntaxhighlight lang="elixir">defmodule RC do
def task(path) do
def task(path) do
plausibility_ratio = 2
plausibility_ratio = 2
Line 1,777: Line 1,777:


path = hd(System.argv)
path = hd(System.argv)
IO.inspect RC.task(path)</lang>
IO.inspect RC.task(path)</syntaxhighlight>


{{out}}
{{out}}
Line 1,790: Line 1,790:


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>
<syntaxhighlight lang="erlang">
-module(cei).
-module(cei).
-export([plaus/0,count/3]).
-export([plaus/0,count/3]).
Line 1,815: Line 1,815:
nomatch -> count(T,Pattern, Acc)
nomatch -> count(T,Pattern, Acc)
end.
end.
</syntaxhighlight>
</lang>
{{output}}
{{output}}
<pre>
<pre>
Line 1,825: Line 1,825:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: combinators formatting generalizations io.encodings.utf8
<syntaxhighlight lang="factor">USING: combinators formatting generalizations io.encodings.utf8
io.files kernel literals math prettyprint regexp sequences ;
io.files kernel literals math prettyprint regexp sequences ;
IN: rosetta-code.i-before-e
IN: rosetta-code.i-before-e
Line 1,847: Line 1,847:


"I before E when not preceded by C"
"I before E when not preceded by C"
"E before I when preceded by C" [ output ] bi@</lang>
"E before I when preceded by C" [ output ] bi@</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,859: Line 1,859:
=={{header|Fortran}}==
=={{header|Fortran}}==
Please find the linux build instructions along with example run in the comments at the beginning of the f90 source. Thank you.
Please find the linux build instructions along with example run in the comments at the beginning of the f90 source. Thank you.
<syntaxhighlight lang="fortran">
<lang FORTRAN>
!-*- mode: compilation; default-directory: "/tmp/" -*-
!-*- mode: compilation; default-directory: "/tmp/" -*-
!Compilation started at Sat May 18 22:19:19
!Compilation started at Sat May 18 22:19:19
Line 1,931: Line 1,931:
end function plausibility
end function plausibility
end program cia
end program cia
</syntaxhighlight>
</lang>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang FreeBASIC>Function getfile(file As String) As String
<syntaxhighlight lang="freebasic">Function getfile(file As String) As String
Dim As Integer F = Freefile
Dim As Integer F = Freefile
Dim As String text,intext
Dim As String text,intext
Line 1,983: Line 1,983:
print "So, the idea is not plausible."
print "So, the idea is not plausible."


Sleep</lang>
Sleep</syntaxhighlight>
{{out}}
{{out}}
<pre>The number of words in unixdict.txt 25104
<pre>The number of words in unixdict.txt 25104
Line 1,999: Line 1,999:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>include "NSLog.incl"
<syntaxhighlight lang="futurebasic">include "NSLog.incl"


#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
Line 2,052: Line 2,052:
fn DoIt
fn DoIt


HandleEvents</lang>
HandleEvents</syntaxhighlight>


{{output}}
{{output}}
Line 2,067: Line 2,067:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 2,134: Line 2,134:
}
}
return false
return false
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,148: Line 2,148:
This solution does not attempt the stretch goal.
This solution does not attempt the stretch goal.


<lang Haskell>import Network.HTTP
<syntaxhighlight lang="haskell">import Network.HTTP
import Text.Regex.TDFA
import Text.Regex.TDFA
import Text.Printf
import Text.Printf
Line 2,172: Line 2,172:
rule2Plausible = numTrueRule2 > (2*numFalseRule2)
rule2Plausible = numTrueRule2 > (2*numFalseRule2)
printf "Rule 2 is correct for %d\n incorrect for %d\n" numTrueRule2 numFalseRule2
printf "Rule 2 is correct for %d\n incorrect for %d\n" numTrueRule2 numFalseRule2
printf "*** Rule 2 is %splausible.\n" (if rule2Plausible then "" else "im")</lang>
printf "*** Rule 2 is %splausible.\n" (if rule2Plausible then "" else "im")</syntaxhighlight>


{{out}}
{{out}}
Line 2,193: Line 2,193:
same input line should all be tested.
same input line should all be tested.


<lang Unicon>import Utils # To get the FindFirst class
<syntaxhighlight lang="unicon">import Utils # To get the FindFirst class


procedure main(a)
procedure main(a)
Line 2,211: Line 2,211:


if \showCounts then every write(phrase := !phrases,": ",totals[phrase])
if \showCounts then every write(phrase := !phrases,": ",totals[phrase])
end</lang>
end</syntaxhighlight>


{{out}} of running with <tt>--showcounts</tt> flag:
{{out}} of running with <tt>--showcounts</tt> flag:
Line 2,228: Line 2,228:
=== stretch goal ===
=== stretch goal ===


<lang Unicon>import Utils # To get the FindFirst class
<syntaxhighlight lang="unicon">import Utils # To get the FindFirst class


procedure main(a)
procedure main(a)
Line 2,252: Line 2,252:


if \showCounts then every write(phrase := !phrases,": ",totals[phrase])
if \showCounts then every write(phrase := !phrases,": ",totals[phrase])
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 2,271: Line 2,271:
After downloading unixdict to /tmp:
After downloading unixdict to /tmp:


<lang J> dict=:tolower fread '/tmp/unixdict.txt'</lang>
<syntaxhighlight lang="j"> dict=:tolower fread '/tmp/unixdict.txt'</syntaxhighlight>


Investigating the rules:
Investigating the rules:


<lang J> +/'cie' E. dict
<syntaxhighlight lang="j"> +/'cie' E. dict
24
24
+/'cei' E. dict
+/'cei' E. dict
Line 2,282: Line 2,282:
490
490
+/'ei' E. dict
+/'ei' E. dict
230</lang>
230</syntaxhighlight>


So, based on unixdict.txt, the "I before E" rule seems plausible (490 > 230 by more than a factor of 2), but the exception does not make much sense (we see almost twice as many i before e after a c as we see e before i after a c).
So, based on unixdict.txt, the "I before E" rule seems plausible (490 > 230 by more than a factor of 2), but the exception does not make much sense (we see almost twice as many i before e after a c as we see e before i after a c).
Line 2,292: Line 2,292:
After downloading 1_2_all_freq to /tmp, we can read it into J, and break out the first column (as words) and the third column as numbers:
After downloading 1_2_all_freq to /tmp, we can read it into J, and break out the first column (as words) and the third column as numbers:


<lang J>allfreq=: |:}.<;._1;._2]1!:1<'/tmp/1_2_all_freq.txt'
<syntaxhighlight lang="j">allfreq=: |:}.<;._1;._2]1!:1<'/tmp/1_2_all_freq.txt'


words=: >0 { allfreq
words=: >0 { allfreq
freqs=: 0 {.@".&>2 { allfreq</lang>
freqs=: 0 {.@".&>2 { allfreq</syntaxhighlight>


With these definitions, we can define a prevalence verb which will tell us how often a particular substring is appears in use:
With these definitions, we can define a prevalence verb which will tell us how often a particular substring is appears in use:


<lang J>prevalence=:verb define
<syntaxhighlight lang="j">prevalence=:verb define
(y +./@E."1 words) +/ .* freqs
(y +./@E."1 words) +/ .* freqs
)</lang>
)</syntaxhighlight>


Investigating our original proposed rules:
Investigating our original proposed rules:


<lang J> 'ie' %&prevalence 'ei'
<syntaxhighlight lang="j"> 'ie' %&prevalence 'ei'
1.76868</lang>
1.76868</syntaxhighlight>


A generic "i before e" rule is not looking quite as good now - words that have i before e are used less than twice as much as words which use e before i.
A generic "i before e" rule is not looking quite as good now - words that have i before e are used less than twice as much as words which use e before i.


<lang J> 'cei' %&prevalence 'cie'
<syntaxhighlight lang="j"> 'cei' %&prevalence 'cie'
0.328974</lang>
0.328974</syntaxhighlight>


An "except after c" variant is looking awful now - words that use the cie sequence are three times as likely as words that use the cei sequence. So, of course, if we modified our original rule with this exception it would weaken the original rule:
An "except after c" variant is looking awful now - words that use the cie sequence are three times as likely as words that use the cei sequence. So, of course, if we modified our original rule with this exception it would weaken the original rule:


<lang J> ('ie' -&prevalence 'cie') % ('ei' -&prevalence 'cei')
<syntaxhighlight lang="j"> ('ie' -&prevalence 'cie') % ('ei' -&prevalence 'cei')
1.68255</lang>
1.68255</syntaxhighlight>


Note that we might also want to consider non-adjacent matches (the regular expression 'i.*e' instead of 'ie' or perhaps 'c.*ie' or 'c.*i.*e' instead of 'cie') - this would be straightforward to check, but this would bulk up the page.
Note that we might also want to consider non-adjacent matches (the regular expression 'i.*e' instead of 'ie' or perhaps 'c.*ie' or 'c.*i.*e' instead of 'cie') - this would be straightforward to check, but this would bulk up the page.
Line 2,323: Line 2,323:
Download and save wordlist to unixdict.txt.
Download and save wordlist to unixdict.txt.


<lang java>
<syntaxhighlight lang="java">
import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileReader;
Line 2,382: Line 2,382:
}
}
}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,393: Line 2,393:


WARNING: The problem statement is misleading as the rule only applies to syllables that rhyme with "see".
WARNING: The problem statement is misleading as the rule only applies to syllables that rhyme with "see".
<lang jq>def plausibility_ratio: 2;
<syntaxhighlight lang="jq">def plausibility_ratio: 2;


# scan/2 produces a stream of matches but the first match of a segment (e.g. cie)
# scan/2 produces a stream of matches but the first match of a segment (e.g. cie)
Line 2,427: Line 2,427:
as ratio = \($x)/\($y) ~ \($ratio * 100 |round)%" ;
as ratio = \($x)/\($y) ~ \($ratio * 100 |round)%" ;


"Using the problematic criterion specified in the task requirements:", assess</lang>
"Using the problematic criterion specified in the task requirements:", assess</syntaxhighlight>
{{out}}
{{out}}
Using http://www.puzzlers.org/pub/wordlists/unixdict.txt as of June 2015:
Using http://www.puzzlers.org/pub/wordlists/unixdict.txt as of June 2015:
<lang sh>$ jq -s -R -r -f I_before_E_except_after_C.jq unixdict.txt
<syntaxhighlight lang="sh">$ jq -s -R -r -f I_before_E_except_after_C.jq unixdict.txt
Using the problematic criterion specified in the task requirements:
Using the problematic criterion specified in the task requirements:
-- the rule "E before I when preceded by C" is implausible
-- the rule "E before I when preceded by C" is implausible
as ratio = 13/24 ~ 54%
as ratio = 13/24 ~ 54%
-- the rule "I before E when not preceded by C" is plausible
-- the rule "I before E when not preceded by C" is plausible
as ratio = 464/217 ~ 214%</lang>
as ratio = 464/217 ~ 214%</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia># v0.0.6
<syntaxhighlight lang="julia"># v0.0.6


open("unixdict.txt") do txtfile
open("unixdict.txt") do txtfile
Line 2,465: Line 2,465:
print("Plausibility of \"E before I when preceded by C\":")
print("Plausibility of \"E before I when preceded by C\":")
println(rule2 > 2 * notrule2 ? "PLAUSIBLE" : "UNPLAUSIBLE")
println(rule2 > 2 * notrule2 ? "PLAUSIBLE" : "UNPLAUSIBLE")
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 2,472: Line 2,472:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


import java.net.URL
import java.net.URL
Line 2,532: Line 2,532:
println()
println()
printResults("British National Corpus", counts2)
printResults("British National Corpus", counts2)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,564: Line 2,564:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang lasso>
<syntaxhighlight lang="lasso">
local(cie,cei,ie,ei) = (:0,0,0,0)
local(cie,cei,ie,ei) = (:0,0,0,0)


Line 2,598: Line 2,598:
)
)
stdoutnl(`Overall the rule is ` + (#ie_plausible and #cei_plausible ? `` | `NOT-`) + `PLAUSIBLE`)
stdoutnl(`Overall the rule is ` + (#ie_plausible and #cei_plausible ? `` | `NOT-`) + `PLAUSIBLE`)
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,607: Line 2,607:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>-- Needed to get dictionary file from web server
<syntaxhighlight lang="lua">-- Needed to get dictionary file from web server
local http = require("socket.http")
local http = require("socket.http")


Line 2,638: Line 2,638:
io.write("Overall the phrase is ")
io.write("Overall the phrase is ")
if not (sub1 and sub2) then io.write("not ") end
if not (sub1 and sub2) then io.write("not ") end
print("plausible.")</lang>
print("plausible.")</syntaxhighlight>
{{out}}
{{out}}
<pre>I before E when not preceded by C: PLAUSIBLE
<pre>I before E when not preceded by C: PLAUSIBLE
Line 2,645: Line 2,645:


=={{header|Maple}}==
=={{header|Maple}}==
<lang Maple>words:= HTTP:-Get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"):
<syntaxhighlight lang="maple">words:= HTTP:-Get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"):
lst := StringTools:-Split(words[2],"\n"):
lst := StringTools:-Split(words[2],"\n"):
xie, cie, cei, xei := 0, 0, 0, 0:
xie, cie, cei, xei := 0, 0, 0, 0:
Line 2,667: Line 2,667:
printf("The first phrase is %s with supporting features %d, anti features %d\n", piecewise(p1, "plausible", "not plausible"), xie, xei);
printf("The first phrase is %s with supporting features %d, anti features %d\n", piecewise(p1, "plausible", "not plausible"), xie, xei);
printf("The seond phrase is %s with supporting features %d, anti features %d\n", piecewise(p2, "plausible", "not plausible"), cei, cie);
printf("The seond phrase is %s with supporting features %d, anti features %d\n", piecewise(p2, "plausible", "not plausible"), cei, cie);
printf("The overall phrase is %s\n", piecewise(p1 and p2, "plausible", "not plausible")):</lang>
printf("The overall phrase is %s\n", piecewise(p1 and p2, "plausible", "not plausible")):</syntaxhighlight>
{{Out|Output}}
{{Out|Output}}
<pre>The first phrase is plausible with supporting features 465 and anti features 213
<pre>The first phrase is plausible with supporting features 465 and anti features 213
Line 2,674: Line 2,674:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang mathematica>wordlist =
<syntaxhighlight lang="mathematica">wordlist =
Import["http://wiki.puzzlers.org/pub/wordlists/unixdict.txt",
Import["http://wiki.puzzlers.org/pub/wordlists/unixdict.txt",
"Words"];
"Words"];
Line 2,700: Line 2,700:
ToString[N[cei/cie]]]
ToString[N[cei/cie]]]
Print["Overall the rule is " <>
Print["Overall the rule is " <>
If[test1 && test2, "PLAUSIBLE", "NOT PLAUSIBLE" ]]</lang>
If[test1 && test2, "PLAUSIBLE", "NOT PLAUSIBLE" ]]</syntaxhighlight>


{{out}}
{{out}}
<lang mathematica>The number of words in unixdict.txt = 25104
<syntaxhighlight lang="mathematica">The number of words in unixdict.txt = 25104
The rule "I before E when not preceded by C" is PLAUSIBLE
The rule "I before E when not preceded by C" is PLAUSIBLE
There were 465 examples and 213 counter examples, for a ratio of 2.1831
There were 465 examples and 213 counter examples, for a ratio of 2.1831
Line 2,709: Line 2,709:
There were 13 examples and 24 counter examples, for a ratio of 0.541667
There were 13 examples and 24 counter examples, for a ratio of 0.541667
Overall the rule is NOT PLAUSIBLE
Overall the rule is NOT PLAUSIBLE
</syntaxhighlight>
</lang>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
{{incomplete|MATLAB|Is the original phrase plausible?}}
{{incomplete|MATLAB|Is the original phrase plausible?}}


<lang MATLAB>function i_before_e_except_after_c(f)
<syntaxhighlight lang="matlab">function i_before_e_except_after_c(f)


fid = fopen(f,'r');
fid = fopen(f,'r');
Line 2,746: Line 2,746:
end
end
printf('E before I when preceded by C: is%s plausible\n',v);
printf('E before I when preceded by C: is%s plausible\n',v);
</syntaxhighlight>
</lang>


<pre>octave:23> i_before_e_except_after_c 1_2_all_freq.txt
<pre>octave:23> i_before_e_except_after_c 1_2_all_freq.txt
Line 2,764: Line 2,764:


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE IEC;
<syntaxhighlight lang="modula2">MODULE IEC;
IMPORT SeqIO;
IMPORT SeqIO;
IMPORT Texts;
IMPORT Texts;
Line 2,859: Line 2,859:
WriteString("plausible.");
WriteString("plausible.");
WriteLn;
WriteLn;
END IEC.</lang>
END IEC.</syntaxhighlight>
{{out}}
{{out}}
<pre>Amount of words: 50209
<pre>Amount of words: 50209
Line 2,872: Line 2,872:


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


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


{{out}}
{{out}}
Line 2,914: Line 2,914:
=={{header|Objeck}}==
=={{header|Objeck}}==
{{trans|Seed7}}
{{trans|Seed7}}
<lang objeck>
<syntaxhighlight lang="objeck">
use HTTP;
use HTTP;
use Collection;
use Collection;
Line 2,976: Line 2,976:
}
}
}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,990: Line 2,990:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl
use warnings;
use warnings;
use strict;
use strict;
Line 3,023: Line 3,023:
$result += result($support, $against);
$result += result($support, $against);


print 'Overall: ', 'NOT ' x ($result < 2), "PLAUSIBLE.\n";</lang>
print 'Overall: ', 'NOT ' x ($result < 2), "PLAUSIBLE.\n";</syntaxhighlight>


{{out}}
{{out}}
Line 3,032: Line 3,032:
===Perl: Stretch Goal===
===Perl: Stretch Goal===
Just replace the while loop with the following one:
Just replace the while loop with the following one:
<lang perl>while (<>) {
<syntaxhighlight lang="perl">while (<>) {
my @columns = split;
my @columns = split;
next if 3 < @columns;
next if 3 < @columns;
Line 3,039: Line 3,039:
$count{$k} += $freq if -1 != index $word, $k;
$count{$k} += $freq if -1 != index $word, $k;
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>I before E when not preceded by C: 8148 / 4826 = 1.69. NOT PLAUSIBLE
<pre>I before E when not preceded by C: 8148 / 4826 = 1.69. NOT PLAUSIBLE
Line 3,047: Line 3,047:
=={{header|Phix}}==
=={{header|Phix}}==
Kept dirt simple, difficult to imagine any other approach being faster than this.
Kept dirt simple, difficult to imagine any other approach being faster than this.
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\IbeforeE.exw</span>
<span style="color: #000080;font-style:italic;">-- demo\rosetta\IbeforeE.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 3,085: Line 3,085:
<span style="color: #000000;">show_plausibility</span><span style="color: #0000FF;">(</span> <span style="color: #008000;">"i before e in general"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xie</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cie</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xei</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cei</span> <span style="color: #0000FF;">);</span>
<span style="color: #000000;">show_plausibility</span><span style="color: #0000FF;">(</span> <span style="color: #008000;">"i before e in general"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xie</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cie</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xei</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cei</span> <span style="color: #0000FF;">);</span>
<span style="color: #000000;">show_plausibility</span><span style="color: #0000FF;">(</span> <span style="color: #008000;">"e before i in general"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xei</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cei</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xie</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cie</span> <span style="color: #0000FF;">)</span>
<span style="color: #000000;">show_plausibility</span><span style="color: #0000FF;">(</span> <span style="color: #008000;">"e before i in general"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xei</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cei</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xie</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">cie</span> <span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
Although the output matches, I decided to use different metrics from ALGOL 68 for the middle two conclusions.<br>
Although the output matches, I decided to use different metrics from ALGOL 68 for the middle two conclusions.<br>
Line 3,101: Line 3,101:


=={{header|Picat}}==
=={{header|Picat}}==
<lang Picat>main =>
<syntaxhighlight lang="picat">main =>
Words = read_file_lines("unixdict.txt"),
Words = read_file_lines("unixdict.txt"),
IEWords = [Word : Word in Words, find(Word,"ie",_,_)],
IEWords = [Word : Word in Words, find(Word,"ie",_,_)],
Line 3,131: Line 3,131:
False := [Word|False]
False := [Word|False]
end
end
end.</lang>
end.</syntaxhighlight>


{{out}}
{{out}}
Line 3,141: Line 3,141:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de ibEeaC (File . Prg)
<syntaxhighlight lang="picolisp">(de ibEeaC (File . Prg)
(let
(let
(Cie (let N 0 (in File (while (from "cie") (run Prg))))
(Cie (let N 0 (in File (while (from "cie") (run Prg))))
Line 3,171: Line 3,171:


(ibEeaC "1_2_all_freq.txt"
(ibEeaC "1_2_all_freq.txt"
(inc 'N (format (stem (line) "\t"))) )</lang>
(inc 'N (format (stem (line) "\t"))) )</syntaxhighlight>
Output:
Output:
<pre>cie: 24
<pre>cie: 24
Line 3,190: Line 3,190:


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>iBeforeE: procedure options(main);
<syntaxhighlight lang="pli">iBeforeE: procedure options(main);
declare dict file;
declare dict file;
open file(dict) title('unixdict.txt');
open file(dict) title('unixdict.txt');
Line 3,238: Line 3,238:
if ^(ieNotC & eiC) then put list('not');
if ^(ieNotC & eiC) then put list('not');
put list('plausible.');
put list('plausible.');
end iBeforeE;</lang>
end iBeforeE;</syntaxhighlight>
{{out}}
{{out}}
<pre>CIE: 24
<pre>CIE: 24
Line 3,249: Line 3,249:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang Powershell>$Web = New-Object -TypeName Net.Webclient
<syntaxhighlight lang="powershell">$Web = New-Object -TypeName Net.Webclient
$Words = $web.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt')
$Words = $web.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt')
Line 3,277: Line 3,277:
if ($Clause1 -and $Clause2)
if ($Clause1 -and $Clause2)
{$MainClause = $True}
{$MainClause = $True}
"The plausibility of the phrase 'I before E except after C' is $MainClause"</lang>
"The plausibility of the phrase 'I before E except after C' is $MainClause"</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,286: Line 3,286:


==={{header|Alternative Implementation}}===
==={{header|Alternative Implementation}}===
<lang Powershell>$Web = New-Object -TypeName Net.Webclient
<syntaxhighlight lang="powershell">$Web = New-Object -TypeName Net.Webclient
$Words = $web.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt')
$Words = $web.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt')
Line 3,314: Line 3,314:
if ($Clause1 -and $Clause2)
if ($Clause1 -and $Clause2)
{$MainClause = $True}
{$MainClause = $True}
"The plausibility of the phrase 'I before E except after C' is $MainClause"</lang>
"The plausibility of the phrase 'I before E except after C' is $MainClause"</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,323: Line 3,323:
==={{header|Alternative Implementation 2}}===
==={{header|Alternative Implementation 2}}===
A single pass through the wordlist using the regex engine.
A single pass through the wordlist using the regex engine.
<lang Powershell>$webResult = Invoke-WebRequest -Uri http://wiki.puzzlers.org/pub/wordlists/unixdict.txt -UseBasicParsing
<syntaxhighlight lang="powershell">$webResult = Invoke-WebRequest -Uri http://wiki.puzzlers.org/pub/wordlists/unixdict.txt -UseBasicParsing


$cie, $cei, $_ie, $_ei = 0, 0, 0, 0
$cie, $cei, $_ie, $_ei = 0, 0, 0, 0
Line 3,336: Line 3,336:
"I before E when not preceded by C is plausible: $($_ie -gt $_ei)"
"I before E when not preceded by C is plausible: $($_ie -gt $_ei)"
"E before I when preceded by C is plausible: $($cei -gt $cie)"
"E before I when preceded by C is plausible: $($cei -gt $cie)"
"I before E, except after C is plausible: $(($_ie -gt $_ei) -and ($cei -gt $cie))"</lang>
"I before E, except after C is plausible: $(($_ie -gt $_ei) -and ($cei -gt $cie))"</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,345: Line 3,345:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang purebasic>If ReadFile(1,GetPathPart(ProgramFilename())+"wordlist(en).txt")
<syntaxhighlight lang="purebasic">If ReadFile(1,GetPathPart(ProgramFilename())+"wordlist(en).txt")
While Not Eof(1)
While Not Eof(1)
wl$+ReadString(1)+";"
wl$+ReadString(1)+";"
Line 3,367: Line 3,367:
Print("Overall the rule is : ")
Print("Overall the rule is : ")
If cei>cie And ie>ei : PrintN("PLAUSIBLE") : Else : PrintN("NOT PLAUSIBLE") : EndIf
If cei>cie And ie>ei : PrintN("PLAUSIBLE") : Else : PrintN("NOT PLAUSIBLE") : EndIf
Input()</lang>
Input()</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,383: Line 3,383:


=={{header|Python}}==
=={{header|Python}}==
<lang python>import urllib.request
<syntaxhighlight lang="python">import urllib.request
import re
import re


Line 3,419: Line 3,419:


print('Checking plausibility of "I before E except after C":')
print('Checking plausibility of "I before E except after C":')
print_result(*simple_stats())</lang>
print_result(*simple_stats())</syntaxhighlight>


{{out}}
{{out}}
Line 3,435: Line 3,435:
===Python: Stretch Goal===
===Python: Stretch Goal===
Add the following to the bottom of the previous program:
Add the following to the bottom of the previous program:
<lang python>def stretch_stats(url='http://ucrel.lancs.ac.uk/bncfreq/lists/1_2_all_freq.txt'):
<syntaxhighlight lang="python">def stretch_stats(url='http://ucrel.lancs.ac.uk/bncfreq/lists/1_2_all_freq.txt'):
freq = [line.strip().lower().split()
freq = [line.strip().lower().split()
for line in urllib.request.urlopen(url)
for line in urllib.request.urlopen(url)
Line 3,450: Line 3,450:
print('\n\nChecking plausibility of "I before E except after C"')
print('\n\nChecking plausibility of "I before E except after C"')
print('And taking account of word frequencies in British English:')
print('And taking account of word frequencies in British English:')
print_result(*stretch_stats())</lang>
print_result(*stretch_stats())</syntaxhighlight>


{{out|Produces this extra output}}
{{out|Produces this extra output}}
Line 3,468: Line 3,468:
=={{header|QBasic}}==
=={{header|QBasic}}==
{{trans|BASIC}}
{{trans|BASIC}}
<lang QBasic>DEFINT A-Z
<syntaxhighlight lang="qbasic">DEFINT A-Z
DIM W AS STRING
DIM W AS STRING
CLS
CLS
Line 3,489: Line 3,489:
PRINT "E before I when preceded by C: ";
PRINT "E before I when preceded by C: ";
IF 2 * CE <= XE THEN PRINT "not ";
IF 2 * CE <= XE THEN PRINT "not ";
PRINT "plausible."</lang>
PRINT "plausible."</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang rsplus>words = tolower(readLines("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"))
<syntaxhighlight lang="rsplus">words = tolower(readLines("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"))
ie.npc = sum(grepl("(?<!c)ie", words, perl = T))
ie.npc = sum(grepl("(?<!c)ie", words, perl = T))
ei.npc = sum(grepl("(?<!c)ei", words, perl = T))
ei.npc = sum(grepl("(?<!c)ei", words, perl = T))
Line 3,503: Line 3,503:
message("(1) is ", (if (p1) "" else "not "), "plausible.")
message("(1) is ", (if (p1) "" else "not "), "plausible.")
message("(2) is ", (if (p2) "" else "not "), "plausible.")
message("(2) is ", (if (p2) "" else "not "), "plausible.")
message("The whole phrase is ", (if (p1 && p2) "" else "not "), "plausible.")</lang>
message("The whole phrase is ", (if (p1 && p2) "" else "not "), "plausible.")</syntaxhighlight>


{{out}}
{{out}}
Line 3,511: Line 3,511:


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


(define (get-tallies filename line-parser . patterns)
(define (get-tallies filename line-parser . patterns)
Line 3,542: Line 3,542:


(plausibility "Dictionary" "unixdict.txt" (λ (line) (list line 1))) (newline)
(plausibility "Dictionary" "unixdict.txt" (λ (line) (list line 1))) (newline)
(plausibility "Word frequencies (stretch goal)" "1_2_all_freq.txt" parse-frequency-data)</lang>
(plausibility "Word frequencies (stretch goal)" "1_2_all_freq.txt" parse-frequency-data)</syntaxhighlight>


{{out}}
{{out}}
Line 3,562: Line 3,562:
(formerly Perl 6)
(formerly Perl 6)
This solution uses grammars and actions to parse the given file, the <tt>Bag</tt> for tallying up occurrences of each possible thing we're looking for ("ie", "ei", "cie", and "cei"), and junctions to determine the plausibility of a phrase from the subphrases. Note that a version of rakudo newer than the January 2014 compiler or Star releases is needed, as this code relies on a recent bugfix to the <tt>make</tt> function.
This solution uses grammars and actions to parse the given file, the <tt>Bag</tt> for tallying up occurrences of each possible thing we're looking for ("ie", "ei", "cie", and "cei"), and junctions to determine the plausibility of a phrase from the subphrases. Note that a version of rakudo newer than the January 2014 compiler or Star releases is needed, as this code relies on a recent bugfix to the <tt>make</tt> function.
<lang perl6>grammar CollectWords {
<syntaxhighlight lang="raku" line>grammar CollectWords {
token TOP {
token TOP {
[^^ <word> $$ \n?]+
[^^ <word> $$ \n?]+
Line 3,629: Line 3,629:
plausible($results<cei>, $results<cie>, "E before I when preceded by C");
plausible($results<cei>, $results<cie>, "E before I when preceded by C");


say "I before E except after C: ", $phrasetest ?? "PLAUSIBLE" !! "NOT PLAUSIBLE";</lang>
say "I before E except after C: ", $phrasetest ?? "PLAUSIBLE" !! "NOT PLAUSIBLE";</syntaxhighlight>


{{out}}
{{out}}
Line 3,652: Line 3,652:


This solution requires just a few modifications to the grammar and actions from the non-stretch goal.
This solution requires just a few modifications to the grammar and actions from the non-stretch goal.
<lang perl6>grammar CollectWords {
<syntaxhighlight lang="raku" line>grammar CollectWords {
token TOP {
token TOP {
^^ \t Word \t PoS \t Freq $$ \n
^^ \t Word \t PoS \t Freq $$ \n
Line 3,717: Line 3,717:
plausible($results<cei>, $results<cie>, "E before I when preceded by C");
plausible($results<cei>, $results<cie>, "E before I when preceded by C");


say "I before E except after C: ", $phrasetest ?? "PLAUSIBLE" !! "NOT PLAUSIBLE";</lang>
say "I before E except after C: ", $phrasetest ?? "PLAUSIBLE" !! "NOT PLAUSIBLE";</syntaxhighlight>


{{out}}
{{out}}
Line 3,727: Line 3,727:
The script processes both the task and the stretch goal.
The script processes both the task and the stretch goal.
In the stretch goal, "rows with three space or tab separated words only" (7574 out of 7726) are processed, excluding all expressions like "out of".
In the stretch goal, "rows with three space or tab separated words only" (7574 out of 7726) are processed, excluding all expressions like "out of".
<lang Red>Red ["i before e except after c"]
<syntaxhighlight lang="red">Red ["i before e except after c"]


testlist: function [wordlist /wfreq] [
testlist: function [wordlist /wfreq] [
Line 3,759: Line 3,759:
keep seq/1 keep to-integer seq/3
keep seq/1 keep to-integer seq/3
]]]
]]]
testlist/wfreq bnclist</lang>
testlist/wfreq bnclist</syntaxhighlight>


{{out}}
{{out}}
Line 3,784: Line 3,784:


===unweighted version===
===unweighted version===
<lang rexx>/*REXX program shows plausibility of "I before E" when not preceded by C, and */
<syntaxhighlight lang="rexx">/*REXX program shows plausibility of "I before E" when not preceded by C, and */
/*───────────────────────────────────── "E before I" when preceded by C. */
/*───────────────────────────────────── "E before I" when preceded by C. */
parse arg iFID . /*obtain optional argument from the CL.*/
parse arg iFID . /*obtain optional argument from the CL.*/
Line 3,819: Line 3,819:
else #.x.z=#.x.z + 1
else #.x.z=#.x.z + 1
s=_ + 1 /*handle the cases of multiple finds. */
s=_ + 1 /*handle the cases of multiple finds. */
end /*forever*/</lang>
end /*forever*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the default dictionary:}}
{{out|output|text=&nbsp; when using the default dictionary:}}
<pre>
<pre>
Line 3,855: Line 3,855:


A cursory look at the file seems to indicate that the use of the tilde and/or asterisk doesn't affect the rules for the mantra phrases.
A cursory look at the file seems to indicate that the use of the tilde and/or asterisk doesn't affect the rules for the mantra phrases.
<lang rexx>/*REXX program shows plausibility of "I before E" when not preceded by C, and */
<syntaxhighlight lang="rexx">/*REXX program shows plausibility of "I before E" when not preceded by C, and */
/*───────────────────────────────────── "E before I" when preceded by C, using a */
/*───────────────────────────────────── "E before I" when preceded by C, using a */
/*───────────────────────────────────── weighted frequency for each word. */
/*───────────────────────────────────── weighted frequency for each word. */
Line 3,915: Line 3,915:
if substr(u, _ - 1 + (_==1)*999, 1)=='C' then #.x.c=#.x.c + one
if substr(u, _ - 1 + (_==1)*999, 1)=='C' then #.x.c=#.x.c + one
else #.x.z=#.x.z + one
else #.x.z=#.x.z + one
s=_ + 1 /*handle the cases of multiple finds. */</lang>
s=_ + 1 /*handle the cases of multiple finds. */</syntaxhighlight>
{{out|output|text=&nbsp; when using the default dictionary and default word frequency list:}}
{{out|output|text=&nbsp; when using the default dictionary and default word frequency list:}}
<pre>
<pre>
Line 3,936: Line 3,936:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : I before E except after C
# Project : I before E except after C


Line 3,976: Line 3,976:
end
end
return sum
return sum
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 3,990: Line 3,990:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>require 'open-uri'
<syntaxhighlight lang="ruby">require 'open-uri'


plausibility_ratio = 2
plausibility_ratio = 2
Line 4,009: Line 4,009:


puts "Overall: #{overall_plausible ? 'Plausible' : 'Implausible'}."
puts "Overall: #{overall_plausible ? 'Plausible' : 'Implausible'}."
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 4,020: Line 4,020:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>use std::default::Default;
<syntaxhighlight lang="rust">use std::default::Default;
use std::ops::AddAssign;
use std::ops::AddAssign;


Line 4,099: Line 4,099:
);
);
}
}
</syntaxhighlight>
</lang>
<pre>
<pre>
Counting Feature {
Counting Feature {
Line 4,113: Line 4,113:


=={{header|Scala}}==
=={{header|Scala}}==
<lang Scala>object I_before_E_except_after_C extends App {
<syntaxhighlight lang="scala">object I_before_E_except_after_C extends App {
val testIE1 = "(^|[^c])ie".r // i before e when not preceded by c
val testIE1 = "(^|[^c])ie".r // i before e when not preceded by c
val testIE2 = "cie".r // i before e when preceded by c
val testIE2 = "cie".r // i before e when preceded by c
Line 4,135: Line 4,135:
println("E before I when preceded by C: "+plausibility(countsCEI))
println("E before I when preceded by C: "+plausibility(countsCEI))
println("Overall: "+plausibility(plausible(countsIE) && plausible(countsCEI)))
println("Overall: "+plausibility(plausible(countsIE) && plausible(countsCEI)))
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>I before E when not preceded by C: plausible
<pre>I before E when not preceded by C: plausible
Line 4,142: Line 4,142:


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "gethttp.s7i";
include "gethttp.s7i";
include "float.s7i";
include "float.s7i";
Line 4,200: Line 4,200:
writeln("(To be plausible, one word count must exceed another by " <& PLAUSIBILITY_RATIO <& " times)");
writeln("(To be plausible, one word count must exceed another by " <& PLAUSIBILITY_RATIO <& " times)");
end if;
end if;
end func;</lang>
end func;</syntaxhighlight>


{{out}}
{{out}}
Line 4,215: Line 4,215:
=={{header|Swift}}==
=={{header|Swift}}==
Using [https://github.com/johnno1962/SwiftRegex/blob/master/SwiftRegex.swift SwiftRegex] for easy regex in strings.
Using [https://github.com/johnno1962/SwiftRegex/blob/master/SwiftRegex.swift SwiftRegex] for easy regex in strings.
<lang Swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


let request = NSURLRequest(URL: NSURL(string: "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")!)
let request = NSURLRequest(URL: NSURL(string: "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")!)
Line 4,269: Line 4,269:
}
}


CFRunLoopRun()</lang>
CFRunLoopRun()</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,279: Line 4,279:
=={{header|True BASIC}}==
=={{header|True BASIC}}==
{{trans|BASIC}}
{{trans|BASIC}}
<lang qbasic>DEF EOF(f)
<syntaxhighlight lang="qbasic">DEF EOF(f)
IF END #f THEN LET EOF = -1 ELSE LET EOF = 0
IF END #f THEN LET EOF = -1 ELSE LET EOF = 0
END DEF
END DEF
Line 4,307: Line 4,307:
IF 2*ce <= xe THEN PRINT "not ";
IF 2*ce <= xe THEN PRINT "not ";
PRINT "plausible."
PRINT "plausible."
END</lang>
END</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{trans|Python}}<!-- very approximately, mainly for the messages -->
{{trans|Python}}<!-- very approximately, mainly for the messages -->
<lang tcl>package require http
<syntaxhighlight lang="tcl">package require http


variable PLAUSIBILITY_RATIO 2.0
variable PLAUSIBILITY_RATIO 2.0
Line 4,352: Line 4,352:
}
}
puts "\n(To be plausible, one word count must exceed another by\
puts "\n(To be plausible, one word count must exceed another by\
$PLAUSIBILITY_RATIO times)"</lang>
$PLAUSIBILITY_RATIO times)"</syntaxhighlight>
{{out}}
{{out}}
<!-- note that checking the pronunciation of the words indicates a key guard on the real rule that isn't normally stated -->
<!-- note that checking the pronunciation of the words indicates a key guard on the real rule that isn't normally stated -->
Line 4,370: Line 4,370:


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT,{}
$$ MODE TUSCRIPT,{}
words=REQUEST("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
words=REQUEST("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
Line 4,433: Line 4,433:


TRAcE *check1,check2,checkall
TRAcE *check1,check2,checkall
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 4,449: Line 4,449:
=={{header|uBasic/4tH}}==
=={{header|uBasic/4tH}}==
{{trans|PowerShell}}
{{trans|PowerShell}}
<lang>If Set(a, Open ("unixdict.txt", "r")) < 0 Then Print "Cannot open \qunixdict.txt\q" : End
<syntaxhighlight lang="text">If Set(a, Open ("unixdict.txt", "r")) < 0 Then Print "Cannot open \qunixdict.txt\q" : End


x = Set (y, Set (p, Set (q, 0)))
x = Set (y, Set (p, Set (q, 0)))
Line 4,479: Line 4,479:
If Comp(Clip(Chop(a@,c@),Len(a@)-c@-Len(b@)),b@)=0 Then Unloop : Return (c@)
If Comp(Clip(Chop(a@,c@),Len(a@)-c@-Len(b@)),b@)=0 Then Unloop : Return (c@)
Next
Next
Return (-1)</lang>
Return (-1)</syntaxhighlight>
{{Out}}
{{Out}}
<pre>The plausibility of 'I before E when not preceded by C' is True
<pre>The plausibility of 'I before E when not preceded by C' is True
Line 4,488: Line 4,488:


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
<lang bash>#!/bin/sh
<syntaxhighlight lang="bash">#!/bin/sh


matched() {
matched() {
Line 4,515: Line 4,515:
echo "Overall, the rule is not plausible"
echo "Overall, the rule is not plausible"
fi
fi
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 4,525: Line 4,525:
=={{header|VBScript}}==
=={{header|VBScript}}==
The sample text was downloaded and saved in the same folder as the script.
The sample text was downloaded and saved in the same folder as the script.
<syntaxhighlight lang="vb">
<lang vb>
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set srcFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
Set srcFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
Line 4,574: Line 4,574:
srcFile.Close
srcFile.Close
Set objFSO = Nothing
Set objFSO = Nothing
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 4,591: Line 4,591:
Regex implementation does not technically conform to specification because it counts the number of occurrences of "ie" and "ei" instead of the number of words.
Regex implementation does not technically conform to specification because it counts the number of occurrences of "ie" and "ei" instead of the number of words.


<lang vbnet>Option Compare Binary
<syntaxhighlight lang="vbnet">Option Compare Binary
Option Explicit On
Option Explicit On
Option Infer On
Option Infer On
Line 4,726: Line 4,726:
End Sub
End Sub
End Module
End Module
</syntaxhighlight>
</lang>


{{out|case=Loop implementation}}
{{out|case=Loop implementation}}
Line 4,777: Line 4,777:


Also there are seven words which fall into two categories and which have therefore been double-counted.
Also there are seven words which fall into two categories and which have therefore been double-counted.
<lang ecmascript>import "io" for File
<syntaxhighlight lang="ecmascript">import "io" for File
import "/pattern" for Pattern
import "/pattern" for Pattern
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 4,828: Line 4,828:
Fmt.print(" Plausible : $s", yesNo.call(plaus2))
Fmt.print(" Plausible : $s", yesNo.call(plaus2))


Fmt.print("\nPlausible overall: $s", yesNo.call(plaus && plaus2))</lang>
Fmt.print("\nPlausible overall: $s", yesNo.call(plaus && plaus2))</syntaxhighlight>


{{out}}
{{out}}
Line 4,859: Line 4,859:
And the code and results for the 'stretch goal' which has just the one double-counted word:
And the code and results for the 'stretch goal' which has just the one double-counted word:


<lang ecmascript>import "io" for File
<syntaxhighlight lang="ecmascript">import "io" for File
import "/pattern" for Pattern
import "/pattern" for Pattern
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 4,916: Line 4,916:
Fmt.print(" Plausible : $s", yesNo.call(plaus2))
Fmt.print(" Plausible : $s", yesNo.call(plaus2))


Fmt.print("\nPlausible overall: $s", yesNo.call(plaus && plaus2))</lang>
Fmt.print("\nPlausible overall: $s", yesNo.call(plaus && plaus2))</syntaxhighlight>


{{out}}
{{out}}
Line 4,942: Line 4,942:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
{{trans|BASIC}}
{{trans|BASIC}}
<lang freebasic>open "unixdict.txt" for reading as #1
<syntaxhighlight lang="freebasic">open "unixdict.txt" for reading as #1


repeat
repeat
Line 4,965: Line 4,965:
if 2 * CE <= XE then print "not "; : fi
if 2 * CE <= XE then print "not "; : fi
print "plausible."
print "plausible."
end</lang>
end</syntaxhighlight>




=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>fcn wcnt(wordList,altrs,aAdjust,bltrs,bAdjust,text){
<syntaxhighlight lang="zkl">fcn wcnt(wordList,altrs,aAdjust,bltrs,bAdjust,text){
a:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(altrs) },0) - aAdjust;
a:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(altrs) },0) - aAdjust;
b:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(bltrs) },0) - bAdjust;
b:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(bltrs) },0) - bAdjust;
Line 4,977: Line 4,977:
return(a,b,ratio);
return(a,b,ratio);
}
}
wordList:=File("unixdict.txt").read();</lang>
wordList:=File("unixdict.txt").read();</syntaxhighlight>
<lang zkl>a,b,r1:=wcnt(wordList,"cei",0,"cie",0,"E before I when preceded by C");
<syntaxhighlight lang="zkl">a,b,r1:=wcnt(wordList,"cei",0,"cie",0,"E before I when preceded by C");
_,_,r2:=wcnt(wordList,"ie",b,"ei",a, "I before E when not preceded by C");
_,_,r2:=wcnt(wordList,"ie",b,"ei",a, "I before E when not preceded by C");
"Overall the rule is %splausible".fmt((r1<2 or r2<2) and "im" or "").println();</lang>
"Overall the rule is %splausible".fmt((r1<2 or r2<2) and "im" or "").println();</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,990: Line 4,990:
</pre>
</pre>
Stretch
Stretch
<lang zkl>fcn wc2(wordList,altrs,aAdjust,bltrs,bAdjust,text){
<syntaxhighlight lang="zkl">fcn wc2(wordList,altrs,aAdjust,bltrs,bAdjust,text){
a,b:=wordList.reduce('wrap(cnts,line){
a,b:=wordList.reduce('wrap(cnts,line){
// don't care if line is "Word PoS Freq" or "as yet Adv 14"
// don't care if line is "Word PoS Freq" or "as yet Adv 14"
Line 5,004: Line 5,004:
return(a,b,ratio);
return(a,b,ratio);
}
}
wordList:=File("1_2_all_freq.txt").read();</lang>
wordList:=File("1_2_all_freq.txt").read();</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>