How to resolve the algorithm I before E except after C step by step in the Delphi programming language
How to resolve the algorithm I before E except after C step by step in the Delphi 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 Delphi programming language
Source code in the delphi programming language
program I_before_E_except_after_C;
uses
System.SysUtils, System.IOUtils;
function IsOppPlausibleWord(w: string): Boolean;
begin
if ((not w.Contains('c')) and (w.Contains('ei'))) then
exit(True);
if (w.Contains('cie')) then
exit(True);
exit(false);
end;
function IsPlausibleWord(w: string): Boolean;
begin
if ((not w.Contains('c')) and (w.Contains('ie'))) then
exit(True);
if (w.Contains('cie')) then
exit(True);
exit(false);
end;
function IsPlausibleRule(filename: TFileName): Boolean;
var
words: TArray;
trueCount, falseCount: Cardinal;
w: string;
begin
words := TFile.ReadAllLines(filename, TEncoding.UTF8);
trueCount := 0;
falseCount := 0;
for w in words do
begin
if (IsPlausibleWord(w)) then
inc(trueCount)
else if (IsOppPlausibleWord(w)) then
inc(falseCount);
end;
Writeln('Plausible count: ', trueCount);
Writeln('Implausible count: ', falseCount);
Result := trueCount > 2 * falseCount;;
end;
begin
if (IsPlausibleRule('unixdict.txt')) then
Writeln('Rule is plausible.')
else
Writeln('Rule is not plausible.');
end.
You may also check:How to resolve the algorithm Unbias a random generator step by step in the GAP programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Oz programming language
You may also check:How to resolve the algorithm Minesweeper game step by step in the Ada programming language
You may also check:How to resolve the algorithm Partial function application step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Terminal control/Cursor positioning step by step in the Scala programming language