How to resolve the algorithm I before E except after C step by step in the jq programming language
How to resolve the algorithm I before E except after C step by step in the jq programming language
Table of Contents
Problem Statement
The phrase "I before E, except after C" is a widely known mnemonic which is supposed to help when spelling English words.
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt, check if the two sub-clauses of the phrase are plausible individually:
If both sub-phrases are plausible then the original phrase can be said to be plausible. Something is plausible if the number of words having the feature is more than two times the number of words having the opposite feature (where feature is 'ie' or 'ei' preceded or not by 'c' as appropriate).
As a stretch goal use the entries from the table of Word Frequencies in Written and Spoken English: based on the British National Corpus, (selecting those rows with three space or tab separated words only), to see if the phrase is plausible when word frequencies are taken into account.
Show your output here as well as your program.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm I before E except after C step by step in the jq programming language
Source code in the jq programming language
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
$ 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%
You may also check:How to resolve the algorithm Pancake numbers step by step in the C++ programming language
You may also check:How to resolve the algorithm SHA-256 step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Dragon curve step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Population count step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Cyclops numbers step by step in the AppleScript programming language