How to resolve the algorithm I before E except after C step by step in the BBC BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm I before E except after C step by step in the BBC BASIC 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 BBC BASIC programming language

Source code in the bbc programming language

      F%=OPENIN"unixdict.txt"
      IF F% == 0 ERROR 100, "unixdict not found!"

      CI=0 : XI=0 : CE=0 : XE=0
      WHILE NOT EOF#F%
        Line$=GET$#F%
  
        P%=INSTR(Line$, "ie")
        WHILE P%
          IF MID$(Line$, P% - 1, 1) == "c" CI+=1 ELSE XI+=1
          P%=INSTR(Line$, "ie", P% + 1)
        ENDWHILE
  
        P%=INSTR(Line$, "ei")
        WHILE P%
          IF MID$(Line$, P% - 1, 1) == "c" CE+=1 ELSE XE+=1
          P%=INSTR(Line$, "ei", P% + 1)
        ENDWHILE
      ENDWHILE
      CLOSE#F%

      PRINT "Instances of 'ie', proceeded by a 'c'     = ";CI
      PRINT "Instances of 'ie', NOT proceeded by a 'c' = ";XI
      P1%=XI * 2 > CI
      PRINT "Therefore 'I before E when not preceded by C' is" FNTest(P1%)
      PRINT

      PRINT "Instances of 'ei', proceeded by a 'c'     = ";CE
      PRINT "Instances of 'ei', NOT proceeded by a 'c' = ";XE
      P2%=CE * 2 > XE
      PRINT "Therefore 'E before I when preceded by C' is" FNTest(P2%)
      PRINT

      IF P1% AND P2% PRINT "B"; ELSE PRINT "Not b";
      PRINT "oth sub-phrases are plausible, therefore the phrase " +\
      \     "'I before E, except after C' can be said to be" FNTest(P1% AND P2%) "!"
      END

      DEF FNTest(plausible%)=MID$(" not plausible", 1 - 4 * plausible%)


  

You may also check:How to resolve the algorithm Binary digits step by step in the Ceylon programming language
You may also check:How to resolve the algorithm Abelian sandpile model step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the BASIC256 programming language
You may also check:How to resolve the algorithm Deming's funnel step by step in the PARI/GP programming language