Find words which contains more than 3 e vowels
- Task
Use the dictionary unixdict.txt
Find words which contains more than three e vowels and contains only e vowels.
Show the output here on this page.
- Metrics
- Counting
- Word frequency
- Letter frequency
- Jewels and stones
- I before E except after C
- Bioinformatics/base count
- Count occurrences of a substring
- Remove/replace
- XXXX redacted
- Remove vowels from a string
- Strip block comments
- Strip comments from a string
- Strip a set of characters from a string
- Strip whitespace from a string -- top and tail
- Strip control codes and extended characters from a string
- Anagrams/Derangements/shuffling
- Word wheel
- ABC problem
- Anagrams
- Anagrams/Deranged anagrams
- Permutations/Derangements
- Superpermutation minimisation
- Sattolo cycle
- Knuth shuffle
- Ordered words
- Textonyms (using a phone text pad)
- Find/Search/Determine
- ABC words
- Odd words
- Semordnilap
- String matching
- Alternade words
- Changeable words
- String comparison
- Extract file extension
- Levenshtein distance
- Palindrome detection
- Compare a list of strings
- Longest common prefix
- Longest common suffix
- Longest common substring
- Find common directory path
- Words from neighbour ones
- Change e letters to i in words
- Non-continuous subsequences
- Longest common subsequence
- Longest palindromic substrings
- Longest increasing subsequence
- Words containing "the" substring
- Determine if a string is numeric
- Determine if a string is collapsible
- Determine if a string is squeezable
- Determine if a string has all unique characters
- Determine if a string has all the same characters
- Find words which contains all the vowels
- Find words which contains most consonants
- Find words which contains more than 3 vowels
- Find words which first and last three letters are equals
- Find words which odd letters are consonants and even letters are vowels or vice_versa
- Formatting
- String case
- Align columns
- Literals/String
- Repeat a string
- Brace expansion
- Brace expansion using ranges
- Reverse a string
- Phrase reversals
- Comma quibbling
- Special characters
- String concatenation
- Substring/Top and tail
- Commatizing numbers
- Reverse words in a string
- Suffixation of decimal numbers
- Long literals, with continuations
- Numerical and alphabetical suffixes
- Abbreviations, easy
- Abbreviations, simple
- Abbreviations, automatic
- Song lyrics/poems/Mad Libs/phrases
- 99 Bottles of Beer
- The Twelve Days of Christmas
- The Old lady swallowed a fly
- The Name Game (a song)
- Magic 8-ball
- Mad Libs
- Tokenize
- Word break problem
- Tokenize a string
- Tokenize a string with escaping
- Split a character string based on change of character
- Sequences
Contents
8080 Assembly[edit]
puts: equ 9 ; CP/M syscall to print a string
fopen: equ 15 ; Open file
fread: equ 20 ; Read block
FCB1: equ 5Ch ; File given on command line
dma: equ 80h
org 100h
lxi d,FCB1 ; Try to open file
mvi c,fopen
call 5
inr a ; A=FF = error
jz err
lxi h,word ; Word buffer
block: push h
lxi d,FCB1 ; Read 128-byte block
mvi c,fread
call 5
pop h ; Restore word buffer pointer
lxi d,dma ; Start of block
dcr a ; If A=1, we're done
rz
inr a ; Otherwise, if A<>0, error
jnz err
char: ldax d ; Get character from block
mov m,a ; Copy into word buffer
inx h
cpi 10 ; End of line?
cz line ; Then test this line
inr e ; Next character in block
jnz char ; If rollover, read next block
jmp block
line: mvi m,'$' ; CP/M string terminator
lxi h,word ; Start at beginning
mvi c,0 ; 'E' counter
letter: mov a,m ; Get letter from word
inx h
cpi '$' ; End of string?
jz done
cpi 'a' ; A / I / O / U = not valid
jz no
cpi 'i'
jz no
cpi 'o'
jz no
cpi 'u'
jz no
cpi 'e' ; E?
jnz letter ; If not, try next letter
inr c ; If so, count the E
jmp letter
done: mvi a,3 ; More than 3 Es?
cmp c
jnc no ; If not, then don't print
push d ; Keep buffer pointer
lxi d,word ; Print word
mvi c,puts
call 5
pop d ; Restore buffer pointer
no: lxi h,word ; Start reading at begin of word buffer
ret
err: lxi d,emsg ; Print error
mvi c,puts
jmp 5
emsg: db 'Error$'
word: equ $
- Output:
A>ewords unixdict.txt belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
ALGOL 68[edit]
Interesting to note the word with the most es is "dereference" - a term first used (I believe) in Algol 68...
# find words that contain more than 3 es and no other vowels #
# read the list of words and look for suitable words #
IF FILE input file;
STRING file name = "unixdict.txt";
open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file #
print( ( "Unable to open """ + file name + """", newline ) )
ELSE
# file opened OK #
BOOL at eof := FALSE;
# set the EOF handler for the file #
on logical file end( input file, ( REF FILE f )BOOL:
BEGIN
# note that we reached EOF on the #
# latest read #
at eof := TRUE;
# return TRUE so processing can continue #
TRUE
END
);
INT eeee words := 0;
WHILE STRING word;
get( input file, ( word, newline ) );
NOT at eof
DO
INT e count := 0, other vowel count := 0;
FOR w pos FROM LWB word TO UPB word DO
CHAR c = word[ w pos ];
IF c = "e"
THEN e count +:= 1
ELIF c = "a"
OR c = "i"
OR c = "o"
OR c = "u"
THEN other vowel count +:= 1
FI
OD;
IF e count > 3 AND other vowel count = 0 THEN
eeee words +:= 1;
print( ( whole( eeee words, -5 ), ": ", word, " (", whole( e count, 0 ), ")", newline ) )
FI
OD;
close( input file )
FI
- Output:
1: belvedere (4) 2: dereference (5) 3: elsewhere (4) 4: erlenmeyer (4) 5: evergreen (4) 6: everywhere (4) 7: exegete (4) 8: freewheel (4) 9: nevertheless (4) 10: persevere (4) 11: preference (4) 12: referee (4) 13: seventeen (4) 14: seventeenth (4) 15: telemeter (4) 16: tennessee (4)
AWK[edit]
/e.*e.*e.*e/ && !/a|i|o|u/ {print}
- Output:
$ awk -f ewords.awk unixdict.txt belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
C[edit]
#include <stdio.h>
#define SIZE 256
int check(char *word) {
int e = 0, ok = 1;
for(; *word && ok; word++) {
switch(*word) {
case 'a':
case 'i':
case 'o':
case 'u': ok = 0; break;
case 'e': e++;
}
}
return ok && e > 3;
}
int main() {
FILE *f;
char line[SIZE];
if (!(f = fopen("unixdict.txt", "r"))) {
fprintf(stderr, "Cannot open unixdict.txt\n");
return 1;
}
while (!feof(f)) {
fgets(line, SIZE, f);
if (check(line)) printf("%s", line);
}
fclose(f);
return 0;
}
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Cowgol[edit]
include "cowgol.coh";
include "file.coh";
interface LineCb(line: [uint8]);
sub ForEachLine(file: [FCB], cb: LineCb) is
var buf: uint8[256];
var ptr := &buf[0];
var length := FCBExt(file);
while length != 0 loop
var ch := FCBGetChar(file);
[ptr] := ch;
ptr := @next ptr;
if ch == '\n' then
[ptr] := 0;
ptr := &buf[0];
cb(&buf[0]);
end if;
length := length - 1;
end loop;
end sub;
sub CheckWord implements LineCb is
var ch := line;
var e: uint8 := 0;
loop
case [ch] is
when 0: break;
when 'a': return;
when 'i': return;
when 'o': return;
when 'u': return;
when 'e': e := e + 1;
end case;
ch := @next ch;
end loop;
if e > 3 then
print(line);
end if;
end sub;
var file: FCB;
if FCBOpenIn(&file, "unixdict.txt") != 0 then
print("Cannot open unixdict.txt\n");
ExitWithError();
end if;
ForEachLine(&file, CheckWord);
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
F#[edit]
// Words contains more than 3 e vowels. Nigel Galloway: February 11th., 2021.
let fN g=let n=Map.ofSeq (Seq.countBy id g) in let fN g=not(n.ContainsKey g) in fN 'a' && fN 'i' && fN 'o' && fN 'u' && not(fN 'e') && n.['e']>3
seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter fN|>Seq.iter(printfn "%s")
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Factor[edit]
USING: formatting io io.encodings.ascii io.files kernel math
sequences ;
"unixdict.txt" ascii file-lines
[ [ "aiou" member? ] any? ] reject
[ [ CHAR: e = ] count 3 > ] filter
[ 1 + "%2d: " printf print ] each-index
- Output:
1: belvedere 2: dereference 3: elsewhere 4: erlenmeyer 5: evergreen 6: everywhere 7: exegete 8: freewheel 9: nevertheless 10: persevere 11: preference 12: referee 13: seventeen 14: seventeenth 15: telemeter 16: tennessee
Go[edit]
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"strings"
"unicode/utf8"
)
func main() {
wordList := "unixdict.txt"
b, err := ioutil.ReadFile(wordList)
if err != nil {
log.Fatal("Error reading file")
}
bwords := bytes.Fields(b)
var words []string
outer:
for _, bword := range bwords {
s := string(bword)
if utf8.RuneCountInString(s) >= 4 {
for _, c := range s {
if strings.ContainsRune("aiou", c) {
continue outer
}
}
words = append(words, s)
}
}
wcount := 0
for _, word := range words {
ecount := 0
for _, c := range word {
if c == 'e' {
ecount++
}
}
if ecount > 3 {
wcount++
fmt.Printf("%2d: %s\n", wcount, word)
}
}
}
- Output:
1: belvedere 2: dereference 3: elsewhere 4: erlenmeyer 5: evergreen 6: everywhere 7: exegete 8: freewheel 9: nevertheless 10: persevere 11: preference 12: referee 13: seventeen 14: seventeenth 15: telemeter 16: tennessee
Haskell[edit]
import System.IO
main = withFile "unixdict.txt" ReadMode $ \h -> do
words <- fmap lines $ hGetContents h
putStrLn $ unlines $ filter valid words
valid w = not (any (`elem` "aiou") w) && length (filter (=='e') w) > 3
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Julia[edit]
See Alternade_words#Julia for the foreachword function.
ecount(word) = count(x -> x == 'e', word)
vowelcount(word) = count(x -> x in ['a', 'e', 'i', 'o', 'u'], word)
onlyevowelsmorethan3(word, _) = begin n, m = vowelcount(word), ecount(word); n == m && m > 3 ? word : "" end
foreachword("unixdict.txt", onlyevowelsmorethan3, colwidth=15, numcols=8)
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Pascal[edit]
program EWords;
var
FileVar: Text;
Line: string[255];
I: Integer;
E: Integer;
OK: Boolean;
begin
Assign(FileVar, 'unixdict.txt');
Reset(FileVar);
while not Eof(FileVar) do
begin
ReadLn(FileVar, Line);
E := 0;
OK := True;
for I := 1 to Length(Line) do
begin
OK := OK and (Pos(Line[I], 'aiou') = 0);
if Line[I] = 'e' then E := E + 1
end;
if OK and (E > 3) then
begin
Write(Line);
WriteLn;
end
end
end.
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Perl[edit]
#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/Find_words_which_contains_more_than_3_e_vowels
use warnings;
@ARGV = 'unixdict.txt';
tr/e// > 3 and tr/aiou// == 0 and print while <>;
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Phix[edit]
function note(string word) return find_any("aiou",word)=0 and length(find_all('e',word))>3 end function
sequence notes = filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),note)
printf(1,"%d words: %s\n",{length(notes),join(shorten(notes,"",3))})
- Output:
16 words: belvedere dereference elsewhere ... seventeenth telemeter tennessee
Python[edit]
with open('unixdict.txt', 'rt') as f:
for line in f.readlines():
if not any(c in 'aiou' for c in line) and sum(c=='e' for c in line)>3:
print(line.strip())
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Raku[edit]
Hardly even worth saving as a script file; an easily entered one-liner.
.say for "unixdict.txt".IO.lines.grep: { !/<[aiou]>/ and /e.*e.*e.*e/ };
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
In an attempt to be a little less useless, here's an alternate script that allows you to specify a vowel, the minimum count to search for, and the file to search. Counts base vowels case, and combining accent insensitive; works with any text file, not just word lists. Defaults to finding words with at least 4 'e's in unixdict.txt. Default output is same as above.
unit sub MAIN ($vowel = 'e', $min = 4, $file = 'unixdict.txt');
.say for squish sort
( $file.IO.slurp.words.grep: { ((my $b = .lc.samemark(' ').comb.Bag){$vowel} >= $min) && $b<a e i o u>.sum == $b{$vowel} } )\
».subst(/<[":;,.?!_\[\]]>/, '', :g);
How about: find words with at least 4 'a's in the Les Misérables file used for the Word frequency task?
Command line > raku monovowel a 4 lemiz.txt
- Output:
Caracalla Caracara Salamanca Vâsaphantâ
REXX[edit]
This REXX version doesn't care what order the words in the dictionary are in, nor does it care what
case (lower/upper/mixed) the words are in, the search for the words and vowels is caseless.
It also allows the vowel to be specified, and also the minimum number of the specific vowels to be specified on the command line (CL) as well as the dictionary file identifier.
/*REXX pgm finds words (within an identified dict.) which contain more than three "e"s.*/
parse arg char many iFID . /*obtain optional arguments from the CL*/
if char=='' | char=="," then char= 'e' /*Not specified? Then use the default.*/
if many=='' | many=="," then many= 4 /* " " " " " " */
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
chrU= char; upper chrU /*obtain an uppercase version of char.*/
do #=1 while lines(iFID)\==0 /*read each word in the file (word=X).*/
x= strip( linein( iFID) ) /*pick off a word from the input line. */
@.#= x /*save: the original case of the word.*/
end /*#*/
#= # - 1 /*adjust word count because of DO loop.*/
say copies('─', 30) # "words in the dictionary file: " iFID
finds= 0 /*count of the "eeee" words found. */
vowels= 'aeiou' /*obtain the list of all the vowels. */
upper vowels /*uppercase all the other vowels. */
vowels= space( translate(vowels, , chrU), 0) /*elide the one vowel we're looking for*/
/*process all the words that were found*/
do j=1 for #; $= @.j; upper $ /*obtain word from dict.; uppercase it.*/
if verify(vowels, $, 'M')>0 then iterate /*Does it contain other vowels? Skip it*/
if countstr(chrU, $) < many then iterate /* " " have enough of 'e's? " "*/
finds= finds + 1 /*bump count of only "e" vowels found. */
say right( left(@.j, 30), 40) /*indent original word for readability.*/
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─', 30) finds " words found having " many ' ' copies(char, many) " letters."
- output when using the default inputs:
────────────────────────────── 25104 words in the dictionary file: unixdict.txt belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee ────────────────────────────── 16 words found having 4 eeee letters.
Ring[edit]
load "stdlib.ring"
cStr = read("unixdict.txt")
wordList = str2list(cStr)
char = list(9)
nextwords = []
nr = 0
num = 0
see "working..." + nl
ln = len(wordList)
for n = ln to 1 step -1
if len(wordList[n]) < 6
del(wordList,n)
ok
next
see "Words are:" + nl
for n = 1 to len(wordList)
num = 0
flag = 1
for m = 1 to len(wordList[n])
if isvowel(wordList[n][m])
if wordList[n][m] != "e"
flag = 0
exit
else
num = num + 1
ok
ok
next
if flag = 1 and num > 3
nr = nr + 1
see "" + nr + ". " + wordList[n] + nl
ok
next
see "done..." + nl
Output:
working... Words are: 1. belvedere 2. dereference 3. elsewhere 4. erlenmeyer 5. evergreen 6. everywhere 7. exegete 8. freewheel 9. nevertheless 10. persevere 11. preference 12. referee 13. seventeen 14. seventeenth 15. telemeter 16. tennessee done...
Snobol[edit]
input(.words, 1,, 'unixdict.txt') :s(line)
output = 'Error!' :(end)
line word = words :f(end)
word 'a' | 'i' | 'o' | 'u' :s(line)
word 'e' arb 'e' arb 'e' arb 'e' :f(line)
output = word :(line)
end
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Swift[edit]
import Foundation
func e3(_ word: String) -> Bool {
var ecount = 0
for ch in word {
switch (ch) {
case "a", "A", "i", "I", "o", "O", "u", "U":
return false
case "e", "E":
ecount += 1
default:
break
}
}
return ecount > 3
}
do {
try String(contentsOfFile: "unixdict.txt", encoding: String.Encoding.ascii)
.components(separatedBy: "\n")
.filter{e3($0)}
.enumerated()
.forEach{print(String(format: "%2d. %@", $0.0 + 1, $0.1))}
} catch {
print(error.localizedDescription)
}
- Output:
1. belvedere 2. dereference 3. elsewhere 4. erlenmeyer 5. evergreen 6. everywhere 7. exegete 8. freewheel 9. nevertheless 10. persevere 11. preference 12. referee 13. seventeen 14. seventeenth 15. telemeter 16. tennessee
Wren[edit]
import "io" for File
import "/fmt" for Fmt
var hasAIOU = Fn.new { |word| word.any { |c| "aiou".contains(c) } }
var wordList = "unixdict.txt" // local copy
var words = File.read(wordList).trimEnd().split("\n").where { |w| w.count >= 4 && !hasAIOU.call(w) }.toList
var count = 0
for (word in words) {
if (word.count { |c| c == "e" } > 3) {
count = count + 1
Fmt.print("$2d: $s", count, word)
}
}
- Output:
1: belvedere 2: dereference 3: elsewhere 4: erlenmeyer 5: evergreen 6: everywhere 7: exegete 8: freewheel 9: nevertheless 10: persevere 11: preference 12: referee 13: seventeen 14: seventeenth 15: telemeter 16: tennessee