Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,13 @@
ie-npc = ei-npc = ie-pc = ei-pc = 0
for word of dict.toLowerCase!.match /\S+/g
++ie-npc if /(^|[^c])ie/.test word
++ei-npc if /(^|[^c])ei/.test word
++ie-pc if word.indexOf('cie') > -1
++ei-pc if word.indexOf('cei') > -1
p1 = ie-npc > 2 * ei-npc
p2 = ei-pc > 2 * ie-pc
console.log '(1) is%s plausible.', if p1 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'

View file

@ -0,0 +1,50 @@
Function getfile(file As String) As String
Dim As Integer F = Freefile
Dim As String text,intext
Open file For Input As #F
Line Input #F,text
While Not Eof(F)
Line Input #F,intext
text=text+Chr(10)+intext
Wend
close #F
Return text
End Function
Function TALLY(instring As String,PartString As String) As Integer
Dim count As Integer
var lens2=Len(PartString)
Dim As String s=instring
Dim As Integer position=Instr(s,PartString)
If position=0 Then Return 0
While position>0
count=count+1
position=Instr(position+Lens2,s,PartString)
Wend
Function=count
End Function
Dim As String myfile="unixdict.txt"
Dim As String wordlist= getfile(myfile)
wordlist=lcase(wordlist)
print
print "The number of words in unixdict.txt ",TALLY(wordlist,chr(10))+1
print
dim as integer cei=TALLY(wordlist,"cei")
print "Instances of cei",cei
dim as integer cie=TALLY(wordlist,"cie")
print "Instances of cie",cie
print
dim as integer ei=TALLY(wordlist,"ei")
print "Instances of *ei, where * is not c",ei-cei
dim as integer ie=TALLY(wordlist,"ie")
print "Instances of *ie, where * is not c",ie-cie
print
print "Conclusion:"
print "ie is plausible when not preceeded by c, the ratio is ";(ie-cie)/(ei-cei)
print "ei is not plausible when preceeded by c, the ratio is ";cei/cie
print "So, the idea is not plausible."
Sleep

View file

@ -0,0 +1,33 @@
local(cie,cei,ie,ei) = (:0,0,0,0)
local(match_ie) = regExp(`[^c]ie`)
local(match_ei) = regExp(`[^c]ei`)
with word in include_url(`http://www.puzzlers.org/pub/wordlists/unixdict.txt`)->asString->split("\n")
where #word >> `ie` or #word >> `ei`
do {
#word >> `cie`
? #cie++
#word >> `cei`
? #cei++
#match_ie->reset(-input=#word, -ignoreCase)&find
? #ie++
#match_ei->reset(-input=#word, -ignoreCase)&find
? #ei++
}
local(ie_plausible) = (#ie >= (2 * #ei))
local(cei_plausible) = (#cei >= (2 * #cie))
stdoutnl(
`The rule "I before E when not preceded by C" is ` +
(#ie_plausible ? '' | 'NOT-') + `PLAUSIBLE. There were ` +
#ie + ` examples and ` + #ei + ` counter-examples.`
)
stdoutnl(
`The rule "E before I when preceded by C" is ` +
(#cei_plausible ? `` | `NOT-`) + `PLAUSIBLE. There were ` +
#cei + ` examples and ` + #cie + ` counter-examples.`
)
stdoutnl(`Overall the rule is ` + (#ie_plausible and #cei_plausible ? `` | `NOT-`) + `PLAUSIBLE`)

View file

@ -0,0 +1,55 @@
import Foundation
let request = NSURLRequest(URL: NSURL(string: "http://www.puzzlers.org/pub/wordlists/unixdict.txt")!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue()) {res, data, err in
if (data != nil) {
if let fileAsString = NSString(data: data, encoding: NSUTF8StringEncoding) {
var firstCase = false
var secondCase = false
var cie = 0
var cei = 0
var not_c_ie = 0
var not_c_ei = 0
let words = fileAsString.componentsSeparatedByString("\n")
for word in words {
var wordRegex = RegexMutable(word as String)
if (wordRegex["cie"]) {
cie++
}
if (wordRegex["cei"]) {
cei++
}
if (wordRegex["(^ie|[^c]ie)"].matches().count != 0) {
not_c_ie++
}
if (wordRegex["(^ei|[^c]ei)"].matches().count != 0) {
not_c_ei++
}
}
if (not_c_ie > not_c_ei * 2) {
println("I before E when not preceded by C is plausable")
firstCase = true
} else {
println("I before E when not preceded by C is not plausable")
}
if (cei > cie * 2) {
secondCase = true
println("E before I when preceded by C is plausable")
} else {
println("E before I when preceded by C is not plausable")
}
if (firstCase && secondCase) {
println("I before E except after C is plausible")
} else {
println("I before E except after C is not plausible")
}
}
}
}
CFRunLoopRun()

View file

@ -0,0 +1,35 @@
def plausibility_ratio: 2;
# scan/2 produces a stream of matches but the first match of a segment (e.g. cie)
# blocks further matches with that segment, and therefore if scan produces "ie",
# it was NOT preceded by "c".
def dictionary:
reduce .[] as $word
( {};
reduce ($word | scan("ie|ei|cie|cei")) as $found ( .; .[$found] += 1 ));
def rules:
{ "I before E when not preceded by C": ["ie", "ei"],
"E before I when preceded by C": ["cei", "cie"]
};
# Round to nearest integer or else "round-up"
def round:
if . < 0 then (-1 * ((- .) | round) | if . == -0 then 0 else . end)
else floor as $x | if (. - $x) < 0.5 then $x else $x+1 end
end;
def assess:
(split("\n") | dictionary) as $dictionary
| rules as $rules
| ($rules | keys[]) as $key
| $rules[$key] as $fragments
| $dictionary[$fragments[0]] as $x
| $dictionary[$fragments[1]] as $y
| ($x / $y) as $ratio
| (if $ratio > plausibility_ratio then "plausible"
else "implausible" end) as $plausibility
| " -- the rule \"\($key)\" is \($plausibility)
as ratio = \($x)/\($y) ~ \($ratio * 100 |round)%" ;
"Using the problematic criterion specified in the task requirements:", assess

View file

@ -0,0 +1,6 @@
$ jq -s -R -r -f I_before_E_except_after_C.jq unixdict.txt
Using the problematic criterion specified in the task requirements:
-- the rule "E before I when preceded by C" is implausible
as ratio = 13/24 ~ 54%
-- the rule "I before E when not preceded by C" is plausible
as ratio = 464/217 ~ 214%