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

Source code in the v programming language

import os
import strconv

fn main() {
	mut cei, mut cie, mut ie, mut ei := f32(0), f32(0), f32(0), f32(0)
    unixdict := os.read_file('./unixdict.txt') or {println('Error: file not found') exit(1)}
	words := unixdict.split_into_lines() 
	println("The number of words in unixdict: ${words.len}")
	for word in words {
		cei += word.count('cei')
		cie += word.count('cie')
		ei += word.count('ei')
		ie += word.count('ie')
	}
	print("Rule: 'e' before 'i' when preceded by 'c' at the ratio of ")
	print("${strconv.f64_to_str_lnd1((cei / cie), 2)} is ")
	if cei > cie {println("plausible.")} else {println("implausible.")}
	println("$cei cases for and $cie cases against.")

	print("Rule: 'i' before 'e' except after 'c' at the ratio of ")
	print("${strconv.f64_to_str_lnd1(((ie - cie) / (ei - cei)), 2)} is ") 
	if ie > ei {println("plausible.")} else {println("implausible.")}
	println("${(ie - cie)} cases for and ${(ei - cei)} cases against.")

	print("Overall the rules are ")
	if cei > cie && ie > ei {println("plausible.")} else {println("implausible.")}
}

  

You may also check:How to resolve the algorithm Extend your language step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the E programming language
You may also check:How to resolve the algorithm Summarize and say sequence step by step in the Perl programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Groovy programming language