Find words which contains more than 3 e vowels: Difference between revisions
(Add Red) |
(Add ed example) |
||
(23 intermediate revisions by 16 users not shown) | |||
Line 15: | Line 15: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">V aiou = ‘aiou’ // to get round ‘bug in MSVC 2017’[https://developercommunity.visualstudio.com/t/bug-with-operator-in-c/565417] |
||
L(word) File(‘unixdict.txt’).read().split("\n") |
L(word) File(‘unixdict.txt’).read().split("\n") |
||
I !any(word.map(c -> c C :aiou)) & sum(word.map(c -> Int(c == ‘e’))) > 3 |
I !any(word.map(c -> c C :aiou)) & sum(word.map(c -> Int(c == ‘e’))) > 3 |
||
print(word)</ |
print(word)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 42: | Line 42: | ||
=={{header|8080 Assembly}}== |
=={{header|8080 Assembly}}== |
||
< |
<syntaxhighlight lang="8080asm">puts: equ 9 ; CP/M syscall to print a string |
||
fopen: equ 15 ; Open file |
fopen: equ 15 ; Open file |
||
fread: equ 20 ; Read block |
fread: equ 20 ; Read block |
||
Line 105: | Line 105: | ||
jmp 5 |
jmp 5 |
||
emsg: db 'Error$' |
emsg: db 'Error$' |
||
word: equ $</ |
word: equ $</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 130: | Line 130: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
In the following solution the input file [https://gitlab.com/amarok8bit/action-rosetta-code/-/blob/master/source/unixdict.txt unixdict.txt] is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used. |
In the following solution the input file [https://gitlab.com/amarok8bit/action-rosetta-code/-/blob/master/source/unixdict.txt unixdict.txt] is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used. |
||
< |
<syntaxhighlight lang="action!">BYTE FUNC Count(CHAR ARRAY text CHAR c) |
||
BYTE i,n |
BYTE i,n |
||
Line 171: | Line 171: | ||
FindWords(fname) |
FindWords(fname) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Find_words_which_contains_more_than_3_e_vowels.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Find_words_which_contains_more_than_3_e_vowels.png Screenshot from Atari 8-bit computer] |
||
Line 180: | Line 180: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
with Ada.Strings.Maps; |
with Ada.Strings.Maps; |
||
with Ada.Strings.Fixed; |
with Ada.Strings.Fixed; |
||
Line 210: | Line 210: | ||
end loop; |
end loop; |
||
Close (File); |
Close (File); |
||
end Find_Three_E;</ |
end Find_Three_E;</syntaxhighlight> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Interesting to note the word with the most es is "dereference" - a term first used (I believe) in Algol 68... |
Interesting to note the word with the most es is "dereference" - a term first used (I believe) in Algol 68... |
||
< |
<syntaxhighlight lang="algol68"># find words that contain more than 3 es and no other vowels # |
||
# read the list of words and look for suitable words # |
# read the list of words and look for suitable words # |
||
Line 259: | Line 259: | ||
OD; |
OD; |
||
close( input file ) |
close( input file ) |
||
FI</ |
FI</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 279: | Line 279: | ||
16: tennessee (4) |
16: tennessee (4) |
||
</pre> |
</pre> |
||
=={{header|AppleScript}}== |
|||
<syntaxhighlight lang="applescript">on findWordsWhichContainsMoreThan3EVowels() |
|||
script o |
|||
property wrds : words of ¬ |
|||
(read file ((path to desktop as text) & "unixdict.txt") as «class utf8») |
|||
end script |
|||
set output to {} |
|||
set astid to AppleScript's text item delimiters |
|||
set AppleScript's text item delimiters to "e" |
|||
repeat with thisWord in o's wrds |
|||
set thisWord to thisWord's contents |
|||
if (((count thisWord's text items) > 4) and not ¬ |
|||
((thisWord contains "a") or (thisWord contains "i") or ¬ |
|||
(thisWord contains "o") or (thisWord contains "u"))) then |
|||
set end of output to thisWord |
|||
end if |
|||
end repeat |
|||
set AppleScript's text item delimiters to linefeed |
|||
set output to output as text |
|||
set AppleScript's text item delimiters to astid |
|||
return output |
|||
end findWordsWhichContainsMoreThan3EVowels |
|||
findWordsWhichContainsMoreThan3EVowels()</syntaxhighlight> |
|||
{{output}} |
|||
<syntaxhighlight lang="applescript">"belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee"</syntaxhighlight> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">words: read.lines relative "unixdict.txt" |
||
otherVowels: ["a" "i" "o" "u"] |
otherVowels: ["a" "i" "o" "u"] |
||
containsMoreThan3Es?: function [w][ |
containsMoreThan3Es?: function [w][ |
||
Line 296: | Line 339: | ||
if containsMoreThan3Es? word -> |
if containsMoreThan3Es? word -> |
||
print word |
print word |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 318: | Line 361: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">FileRead, db, % A_Desktop "\unixdict.txt" |
||
vowelsLessE := ["a", "i", "o", "u"] |
vowelsLessE := ["a", "i", "o", "u"] |
||
oRes := [] |
oRes := [] |
||
Line 334: | Line 377: | ||
result .= word "`n" |
result .= word "`n" |
||
} |
} |
||
MsgBox, 262144, , % result</ |
MsgBox, 262144, , % result</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>belvedere |
<pre>belvedere |
||
Line 354: | Line 397: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
< |
<syntaxhighlight lang="awk">/e.*e.*e.*e/ && !/a|i|o|u/ {print}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 378: | Line 421: | ||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<syntaxhighlight lang="bcpl">get "libhdr" |
||
let reads(v) = valof |
let reads(v) = valof |
||
Line 404: | Line 447: | ||
while reads(word) if testword(word) do writef("%S*N",word) |
while reads(word) if testword(word) do writef("%S*N",word) |
||
endread() |
endread() |
||
$)</ |
$)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>belvedere |
<pre>belvedere |
||
Line 424: | Line 467: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#define SIZE 256 |
#define SIZE 256 |
||
Line 458: | Line 501: | ||
fclose(f); |
fclose(f); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 480: | Line 523: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <fstream> |
#include <fstream> |
||
Line 510: | Line 553: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 532: | Line 575: | ||
=={{header|CLU}}== |
=={{header|CLU}}== |
||
< |
<syntaxhighlight lang="clu">e_word = proc (s: string) returns (bool) |
||
e: int := 0 |
e: int := 0 |
||
for c: char in string$chars(s) do |
for c: char in string$chars(s) do |
||
Line 554: | Line 597: | ||
end |
end |
||
stream$close(dict) |
stream$close(dict) |
||
end start_up</ |
end start_up</syntaxhighlight> |
||
{{out}} |
|||
<pre>belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee</pre> |
|||
=={{header|COBOL}}== |
|||
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
|||
PROGRAM-ID. E-WORDS. |
|||
ENVIRONMENT DIVISION. |
|||
INPUT-OUTPUT SECTION. |
|||
FILE-CONTROL. |
|||
SELECT DICT ASSIGN TO DISK |
|||
ORGANIZATION LINE SEQUENTIAL. |
|||
DATA DIVISION. |
|||
FILE SECTION. |
|||
FD DICT |
|||
LABEL RECORD STANDARD |
|||
VALUE OF FILE-ID IS "unixdict.txt". |
|||
01 WORD PIC X(64). |
|||
WORKING-STORAGE SECTION. |
|||
01 E PIC 99. |
|||
01 OTHER PIC 99. |
|||
PROCEDURE DIVISION. |
|||
BEGIN. |
|||
OPEN INPUT DICT. |
|||
READ-WORD. |
|||
READ DICT, AT END CLOSE DICT, STOP RUN. |
|||
PERFORM CHECK-WORD. |
|||
GO TO READ-WORD. |
|||
CHECK-WORD. |
|||
MOVE ZERO TO E, OTHER. |
|||
INSPECT WORD TALLYING OTHER FOR ALL 'a'. |
|||
INSPECT WORD TALLYING E FOR ALL 'e'. |
|||
INSPECT WORD TALLYING OTHER FOR ALL 'i'. |
|||
INSPECT WORD TALLYING OTHER FOR ALL 'o'. |
|||
INSPECT WORD TALLYING OTHER FOR ALL 'u'. |
|||
IF E IS GREATER THAN 3 AND OTHER IS EQUAL TO ZERO, |
|||
DISPLAY WORD.</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre>belvedere |
<pre>belvedere |
||
Line 574: | Line 674: | ||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
< |
<syntaxhighlight lang="cowgol">include "cowgol.coh"; |
||
include "file.coh"; |
include "file.coh"; |
||
Line 622: | Line 722: | ||
end if; |
end if; |
||
ForEachLine(&file, CheckWord);</ |
ForEachLine(&file, CheckWord);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 643: | Line 743: | ||
tennessee |
tennessee |
||
</pre> |
</pre> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|Classes,StdCtrls,SysUtils}} |
|||
This program makes extensive use of the standard Delphi TStringList component. It holds the dictionary, which is preloaded. It capture the E-Vowel-only information in a TStringList and uses it to display the words. |
|||
<syntaxhighlight lang="Delphi"> |
|||
var Dict: TStringList; {List holds dictionary} |
|||
function HasEVowels(S: string): boolean; |
|||
{Test if string has exclusively E-Vowels and no "a,i,o,u"} |
|||
var I,ECount: integer; |
|||
begin |
|||
Result:=False; |
|||
ECount:=0; |
|||
for I:=1 to Length(S) do |
|||
begin |
|||
if S[I] in ['a','i','o','u'] then exit; |
|||
if S[I]='e' then Inc(ECount); |
|||
end; |
|||
Result:=ECount>3; |
|||
end; |
|||
procedure ShowEVowels(Memo: TMemo); |
|||
{Show words in dictionary that only} |
|||
{have e-vowels and have at least three} |
|||
var I: integer; |
|||
var SL: TStringList; |
|||
var S: string; |
|||
begin |
|||
SL:=TStringList.Create; |
|||
try |
|||
{Make list of words with least three E-vowels} |
|||
for I:=0 to Dict.Count-1 do |
|||
if HasEVowels(Dict[I]) then SL.Add(Dict[I]); |
|||
{Display all the words found} |
|||
S:='Found: '+IntToStr(SL.Count)+#$0D#$0A; |
|||
for I:=0 to SL.Count-1 do |
|||
begin |
|||
S:=S+Format('%-23s',[SL[I]]); |
|||
if (I mod 4)=3 then S:=S+#$0D#$0A; |
|||
end; |
|||
Memo.Text:=S; |
|||
finally SL.Free; end; |
|||
end; |
|||
initialization |
|||
{Create/load dictionary} |
|||
Dict:=TStringList.Create; |
|||
Dict.LoadFromFile('unixdict.txt'); |
|||
Dict.Sorted:=True; |
|||
finalization |
|||
Dict.Free; |
|||
end. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Found: 16 |
|||
belvedere dereference elsewhere erlenmeyer |
|||
evergreen everywhere exegete freewheel |
|||
nevertheless persevere preference referee |
|||
seventeen seventeenth telemeter tennessee |
|||
</pre> |
|||
=={{header|Draco}}== |
|||
<syntaxhighlight lang="draco">proc eword(*char line) bool: |
|||
word e; |
|||
char c; |
|||
bool ok; |
|||
ok := true; |
|||
e := 0; |
|||
while |
|||
c := line*; |
|||
line := line + 1; |
|||
ok and c ~= '\e' |
|||
do |
|||
if c='a' or c='i' or c='o' or c='u' then |
|||
ok := false |
|||
elif c='e' then |
|||
e := e + 1 |
|||
fi |
|||
od; |
|||
ok and e>3 |
|||
corp |
|||
proc nonrec main() void: |
|||
file(1024) dictfile; |
|||
[32] char buf; |
|||
*char line; |
|||
channel input text dict; |
|||
open(dict, dictfile, "unixdict.txt"); |
|||
line := &buf[0]; |
|||
while readln(dict; line) do |
|||
if eword(line) then writeln(line) fi |
|||
od; |
|||
close(dict) |
|||
corp</syntaxhighlight> |
|||
{{out}} |
|||
<pre>belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee</pre> |
|||
=={{header|ed}}== |
|||
First remove the short lines, then remove the ones without "the". |
|||
<syntaxhighlight lang="sed"> |
|||
# by Artyom Bologov |
|||
H |
|||
# Remove the words with letters other than e |
|||
g/[aiou]/d |
|||
# Remove the words without three e's |
|||
v/.*e.*e.*e.*e.*/d |
|||
,p |
|||
Q |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>$ ed -s unixdict.txt < e-vowels.ed |
|||
belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Words contains more than 3 e vowels. Nigel Galloway: February 11th., 2021. |
// 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 |
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") |
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") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 671: | Line 929: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: formatting io io.encodings.ascii io.files kernel math |
||
sequences ; |
sequences ; |
||
Line 677: | Line 935: | ||
[ [ "aiou" member? ] any? ] reject |
[ [ "aiou" member? ] any? ] reject |
||
[ [ CHAR: e = ] count 3 > ] filter |
[ [ CHAR: e = ] count 3 > ] filter |
||
[ 1 + "%2d: " printf print ] each-index</ |
[ 1 + "%2d: " printf print ] each-index</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 700: | Line 958: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang="forth">: e3 ( addr u -- ? ) |
||
0 { ecount } |
0 { ecount } |
||
0 do |
0 do |
||
Line 736: | Line 994: | ||
main |
main |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 759: | Line 1,017: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">open "unixdict.txt" for input as #1 |
||
dim as string s, c |
dim as string s, c |
||
Line 773: | Line 1,031: | ||
next i |
next i |
||
if e>3 then print s |
if e>3 then print s |
||
wend</ |
wend</syntaxhighlight> |
||
{{out}}<pre> |
{{out}}<pre> |
||
belvedere |
belvedere |
||
Line 791: | Line 1,049: | ||
telemeter |
telemeter |
||
tennessee |
tennessee |
||
</pre> |
|||
=={{header|Frink}}== |
|||
<syntaxhighlight lang="frink">for word = lines["https://web.archive.org/web/20180611003215if_/http://www.puzzlers.org:80/pub/wordlists/unixdict.txt"] |
|||
{ |
|||
d = countToDict[charList[word]] |
|||
if d.get["a",0] == 0 and d.get["e",0] > 3 and d.get["i",0] == 0 and d.get["o",0] == 0 and d.get["u",0] == 0 |
|||
println[word] |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee |
|||
</pre> |
|||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
include resources "unixdict.txt" |
|||
local fn ThreePlusEWord( string as CFStringRef ) as BOOL |
|||
long i, count = len(string), ecount = 0 |
|||
for i = 0 to count -1 |
|||
unichar ch = fn StringCharacterAtIndex( string, i ) |
|||
select (ch) |
|||
case _"a", _"A", _"i", _"I", _"o", _"O", _"u", _"U" : exit fn = NO |
|||
case _"e", _"E" : ecount++ |
|||
case else : continue |
|||
end select |
|||
next |
|||
if ecount > 3 then exit fn = YES |
|||
end fn = NO |
|||
void local fn CheckWords |
|||
CFURLRef url = fn BundleURLForResource( fn BundleMain, @"unixdict", @"txt", NULL ) |
|||
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL ) |
|||
CFArrayRef words = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet ) |
|||
CFMutableStringRef mutStr = fn MutableStringNew |
|||
NSUInteger count = 1 |
|||
CFStringRef wordStr |
|||
for wordStr in words |
|||
if fn ThreePlusEWord( wordStr ) then MutableStringAppendString( mutStr, fn StringWithFormat( @"%2lu. %@\n", count, wordStr ) ) : count++ |
|||
next |
|||
print mutStr |
|||
end fn |
|||
fn CheckWords |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
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 |
|||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 838: | Line 1,180: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 861: | Line 1,203: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import System.IO |
||
main = withFile "unixdict.txt" ReadMode $ \h -> do |
main = withFile "unixdict.txt" ReadMode $ \h -> do |
||
Line 867: | Line 1,209: | ||
putStrLn $ unlines $ filter valid words |
putStrLn $ unlines $ filter valid words |
||
valid w = not (any (`elem` "aiou") w) && length (filter (=='e') w) > 3</ |
valid w = not (any (`elem` "aiou") w) && length (filter (=='e') w) > 3</syntaxhighlight> |
||
Or, defining the predicate in terms of a single fold: |
|||
<syntaxhighlight lang="haskell">import System.IO (readFile) |
|||
import Data.Bifunctor (first) |
|||
---------- MORE THAN THREE VOWELS, AND NONE BUT E -------- |
|||
p :: String -> Bool |
|||
p = uncurry (&&) . first (3 <) . foldr rule (0, True) |
|||
rule :: Char -> (Int, Bool) -> (Int, Bool) |
|||
rule _ (n, False) = (n, False) |
|||
rule 'e' (n, b) = (succ n, b) |
|||
rule c (n, b) |
|||
| c `elem` "aiou" = (n, False) |
|||
| otherwise = (n, b) |
|||
--------------------------- TEST ------------------------- |
|||
main :: IO () |
|||
main = readFile "unixdict.txt" |
|||
>>= (putStrLn . unlines . filter p . lines) |
|||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre>belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee</pre> |
|||
=={{header|J}}== |
|||
<syntaxhighlight lang="j"> >(#~ (0 4 0 0 0 -: 4 <. +/ .(=/)&'aeiou')@>) cutLF fread'unixdict.txt' |
|||
belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee</syntaxhighlight> |
|||
(Also possible to do this with regular expressions, but this works. Here, we counted how many times each vowel occurred, limited the maximum count to 4, and checked the resulting signature.) |
|||
=={{header|JavaScript}}== |
|||
ECMAScript defines no file operations. Here, to read the dictionary, we use a library available to Apple's "JavaScript for Automation" embedding of a JS interpreter. |
|||
<syntaxhighlight lang="javascript">(() => { |
|||
"use strict"; |
|||
// ----- MORE THAN THREE VOWELS, AND NONE BUT E ------ |
|||
// p :: String -> Bool |
|||
const p = w => { |
|||
// True if the word contains more than three vowels, |
|||
// and none of its vowels are other than "e". |
|||
const |
|||
[noOtherVowels, eCount] = [...w].reduce( |
|||
([bool, n], c) => bool |
|||
? "e" === c |
|||
? [bool, 1 + n] |
|||
: "aiou".includes(c) |
|||
? [false, n] |
|||
: [bool, n] |
|||
: [false, n], |
|||
// Initial accumulator. |
|||
[true, 0] |
|||
); |
|||
return noOtherVowels && (3 < eCount); |
|||
}; |
|||
// ---------------------- TEST ----------------------- |
|||
const main = () => |
|||
lines( |
|||
readFile( |
|||
"~/Desktop/unixdict.txt" |
|||
) |
|||
) |
|||
.filter(p) |
|||
.join("\n"); |
|||
// --------------------- GENERIC --------------------- |
|||
// lines :: String -> [String] |
|||
const lines = s => |
|||
// A list of strings derived from a single string |
|||
// which is delimited by \n or by \r\n or \r. |
|||
0 < s.length |
|||
? s.split(/\r\n|\n|\r/u) |
|||
: []; |
|||
// ----------------------- jxa ----------------------- |
|||
// readFile :: FilePath -> IO String |
|||
const readFile = fp => { |
|||
// The contents of a text file at the |
|||
// given file path. |
|||
const |
|||
e = $(), |
|||
ns = $.NSString |
|||
.stringWithContentsOfFileEncodingError( |
|||
$(fp).stringByStandardizingPath, |
|||
$.NSUTF8StringEncoding, |
|||
e |
|||
); |
|||
return ObjC.unwrap( |
|||
ns.isNil() ? ( |
|||
e.localizedDescription |
|||
) : ns |
|||
); |
|||
}; |
|||
// MAIN --- |
|||
return main(); |
|||
})();</syntaxhighlight> |
|||
{{Out}} |
|||
<pre>belvedere |
<pre>belvedere |
||
dereference |
dereference |
||
Line 893: | Line 1,370: | ||
===Using regular expressions=== |
===Using regular expressions=== |
||
< |
<syntaxhighlight lang="jq">inputs |
||
| select(test("[aiou]")|not) |
| select(test("[aiou]")|not) |
||
| select(test("e.*e.*e.*e"))</ |
| select(test("e.*e.*e.*e"))</syntaxhighlight> |
||
===Regex-free solution=== |
===Regex-free solution=== |
||
< |
<syntaxhighlight lang="jq">def count(s): reduce s as $x (null; .+1); |
||
("aiou" | explode) as $disallow |
("aiou" | explode) as $disallow |
||
Line 906: | Line 1,383: | ||
count(.[] | select(. == 101)) > 3) # "e" is 101 |
count(.[] | select(. == 101)) > 3) # "e" is 101 |
||
| $word |
| $word |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Invocation example: jq -nrR program.jq unixdict.txt |
Invocation example: jq -nrR program.jq unixdict.txt |
||
Line 930: | Line 1,407: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
See [[Alternade_words#Julia]] for the foreachword function. |
See [[Alternade_words#Julia]] for the foreachword function. |
||
< |
<syntaxhighlight lang="julia">ecount(word) = count(x -> x == 'e', word) |
||
vowelcount(word) = count(x -> x in ['a', 'e', 'i', 'o', 'u'], 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 |
onlyevowelsmorethan3(word, _) = begin n, m = vowelcount(word), ecount(word); n == m && m > 3 ? word : "" end |
||
foreachword("unixdict.txt", onlyevowelsmorethan3, colwidth=15, numcols=8) |
foreachword("unixdict.txt", onlyevowelsmorethan3, colwidth=15, numcols=8) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel |
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel |
||
nevertheless persevere preference referee seventeen seventeenth telemeter tennessee |
nevertheless persevere preference referee seventeen seventeenth telemeter tennessee |
||
</pre> |
|||
=={{header|Kotlin}}== |
|||
<syntaxhighlight lang="kotlin"> |
|||
import kotlin.io.path.Path |
|||
import kotlin.io.path.useLines |
|||
fun main() { |
|||
Path("unixdict.txt").useLines { lines -> |
|||
lines |
|||
.filter { line -> line.none { it in "aiou" } } |
|||
.filter { line -> line.count { it == 'e' } > 3 } |
|||
.forEach(::println) |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
{{Output}} |
|||
<pre> |
|||
belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee |
|||
</pre> |
</pre> |
||
=={{header|Ksh}}== |
=={{header|Ksh}}== |
||
< |
<syntaxhighlight lang="ksh"> |
||
#!/bin/ksh |
#!/bin/ksh |
||
Line 978: | Line 1,488: | ||
(( $(_countch "$REPLY" "e") >= MINE )) && print $REPLY |
(( $(_countch "$REPLY" "e") >= MINE )) && print $REPLY |
||
done < ${dictionary} |
done < ${dictionary} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}}<pre> |
{{out}}<pre> |
||
belvedere |
belvedere |
||
Line 998: | Line 1,508: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">vowels = Characters["euioa"]; |
||
dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]]; |
dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]]; |
||
dict //= StringSplit[#, "\n"] &; |
dict //= StringSplit[#, "\n"] &; |
||
Line 1,004: | Line 1,514: | ||
dict //= Select[Last /* Count["e"] /* GreaterThan[3]]; |
dict //= Select[Last /* Count["e"] /* GreaterThan[3]]; |
||
dict //= Select[Last /* Apply[SameQ]]; |
dict //= Select[Last /* Apply[SameQ]]; |
||
dict[[All, 1]]</ |
dict[[All, 1]]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{belvedere, dereference, elsewhere, erlenmeyer, evergreen, everywhere, exegete, freewheel, nevertheless, persevere, preference, referee, seventeen, seventeenth, telemeter, tennessee}</pre> |
<pre>{belvedere, dereference, elsewhere, erlenmeyer, evergreen, everywhere, exegete, freewheel, nevertheless, persevere, preference, referee, seventeen, seventeenth, telemeter, tennessee}</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import strutils |
||
const NonEVowels = ['a', 'i', 'o', 'u'] |
const NonEVowels = ['a', 'i', 'o', 'u'] |
||
Line 1,020: | Line 1,530: | ||
if vowel in word: break checkWord |
if vowel in word: break checkWord |
||
inc count |
inc count |
||
stdout.write word.align(14), if count mod 4 == 0: '\n' else: ' '</ |
stdout.write word.align(14), if count mod 4 == 0: '\n' else: ' '</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,030: | Line 1,540: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Turbo Pascal}} |
{{works with|Turbo Pascal}} |
||
< |
<syntaxhighlight lang="pascal">program EWords; |
||
var |
var |
||
FileVar: Text; |
FileVar: Text; |
||
Line 1,057: | Line 1,567: | ||
end |
end |
||
end |
end |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,079: | Line 1,589: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
use strict; # https://rosettacode.org/wiki/Find_words_which_contains_more_than_3_e_vowels |
use strict; # https://rosettacode.org/wiki/Find_words_which_contains_more_than_3_e_vowels |
||
Line 1,085: | Line 1,595: | ||
@ARGV = 'unixdict.txt'; |
@ARGV = 'unixdict.txt'; |
||
tr/e// > 3 and tr/aiou// == 0 and print while <>;</ |
tr/e// > 3 and tr/aiou// == 0 and print while <>;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
belvedere |
belvedere |
||
Line 1,105: | Line 1,615: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">note</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">find_any</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"aiou"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">find_all</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'e'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">))></span><span style="color: #000000;">3</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">note</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">find_any</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"aiou"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">find_all</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'e'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">))></span><span style="color: #000000;">3</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">notes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">note</span><span style="color: #0000FF;">)</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">notes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">note</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d words: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notes</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notes</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">))})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d words: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notes</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notes</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">))})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,117: | Line 1,627: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang="pli">moreThanThreeEs: procedure options(main); |
||
declare dict file; |
declare dict file; |
||
open file(dict) title('unixdict.txt'); |
open file(dict) title('unixdict.txt'); |
||
Line 1,138: | Line 1,648: | ||
close file(dict); |
close file(dict); |
||
end moreThanThreeEs;</ |
end moreThanThreeEs;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>belvedere |
<pre>belvedere |
||
Line 1,158: | Line 1,668: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">with open('unixdict.txt', 'rt') as f: |
||
for line in f.readlines(): |
for line in f.readlines(): |
||
if not any(c in 'aiou' for c in line) and sum(c=='e' for c in line)>3: |
if not any(c in 'aiou' for c in line) and sum(c=='e' for c in line)>3: |
||
print(line.strip())</ |
print(line.strip())</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,181: | Line 1,691: | ||
telemeter |
telemeter |
||
tennessee</pre> |
tennessee</pre> |
||
=={{header|Quackery}}== |
|||
<syntaxhighlight lang="Quackery"> [ bit |
|||
[ 0 $ "aiou" |
|||
witheach |
|||
[ bit | ] ] constant |
|||
& 0 != ] is aiou ( c --> b ) |
|||
[] |
|||
$ "rosetta/unixdict.txt" sharefile drop nest$ |
|||
witheach |
|||
[ 0 over |
|||
witheach |
|||
[ dup char e = if |
|||
[ dip 1+ ] |
|||
aiou if |
|||
[ drop 0 |
|||
conclude ] ] |
|||
3 > iff |
|||
[ nested join ] |
|||
else drop ] |
|||
50 wrap$</syntaxhighlight> |
|||
{{out}} |
|||
<pre>belvedere dereference elsewhere erlenmeyer |
|||
evergreen everywhere exegete freewheel |
|||
nevertheless persevere preference referee |
|||
seventeen seventeenth telemeter tennessee |
|||
</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
Adapting this from https://rosettacode.org/wiki/Find_words_which_contains_all_the_vowels#R is trivial. |
Adapting this from https://rosettacode.org/wiki/Find_words_which_contains_all_the_vowels#R is trivial. |
||
< |
<syntaxhighlight lang="rsplus">dict <- scan("https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt", what = character()) |
||
#The following line is equivalent to sapply(c("a", "i", "o", "u"), function(x) stringr::str_count(dict, x)) |
#The following line is equivalent to sapply(c("a", "i", "o", "u"), function(x) stringr::str_count(dict, x)) |
||
#As with all things with strings in R, life is easier with stringr or stringi. |
#As with all things with strings in R, life is easier with stringr or stringi. |
||
notEVowelCount <- sapply(c("a", "i", "o", "u"), function(x) lengths(regmatches(dict, gregexec(x, dict)))) |
notEVowelCount <- sapply(c("a", "i", "o", "u"), function(x) lengths(regmatches(dict, gregexec(x, dict)))) |
||
eCount <- lengths(regmatches(dict, gregexec("e", dict))) |
eCount <- lengths(regmatches(dict, gregexec("e", dict))) |
||
dict[apply(notEVowelCount, MARGIN = 1, function(x) all(x < 1)) & eCount > 3]</ |
dict[apply(notEVowelCount, MARGIN = 1, function(x) all(x < 1)) & eCount > 3]</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
;; probably not the best name, but matches the name of the task |
;; probably not the best name, but matches the name of the task |
||
Line 1,211: | Line 1,753: | ||
(module+ main |
(module+ main |
||
qualifying-words)</ |
qualifying-words)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,220: | Line 1,762: | ||
Hardly even worth saving as a script file; an easily entered one-liner. |
Hardly even worth saving as a script file; an easily entered one-liner. |
||
<lang |
<syntaxhighlight lang="raku" line>.say for "unixdict.txt".IO.lines.grep: { !/<[aiou]>/ and /e.*e.*e.*e/ };</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,243: | Line 1,785: | ||
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. |
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. |
||
<lang |
<syntaxhighlight lang="raku" line>unit sub MAIN ($vowel = 'e', $min = 4, $file = 'unixdict.txt'); |
||
.say for squish sort |
.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} } )\ |
( $file.IO.slurp.words.grep: { ((my $b = .lc.samemark(' ').comb.Bag){$vowel} >= $min) && $b<a e i o u>.sum == $b{$vowel} } )\ |
||
».subst(/<[":;,.?!_\[\]]>/, '', :g);</ |
».subst(/<[":;,.?!_\[\]]>/, '', :g);</syntaxhighlight> |
||
How about: find words with at least 4 'a's in the [https://github.com/thundergnat/rc-run/blob/master/rc/resources/lemiz.txt Les Misérables file] used for the [[Word frequency]] task? |
How about: find words with at least 4 'a's in the [https://github.com/thundergnat/rc-run/blob/master/rc/resources/lemiz.txt Les Misérables file] used for the [[Word frequency]] task? |
||
Line 1,259: | Line 1,801: | ||
=={{header|Red}}== |
=={{header|Red}}== |
||
< |
<syntaxhighlight lang="rebol">Red[] |
||
words: read/lines %unixdict.txt |
words: read/lines %unixdict.txt |
||
Line 1,272: | Line 1,814: | ||
] |
] |
||
if all [retain e's > 3] [print word] |
if all [retain e's > 3] [print word] |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,298: | Line 1,840: | ||
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. |
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. |
||
< |
<syntaxhighlight lang="rexx">/*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*/ |
parse arg char many iFID . /*obtain optional arguments from the CL*/ |
||
if char=='' | char=="," then char= 'e' /*Not specified? Then use the default.*/ |
if char=='' | char=="," then char= 'e' /*Not specified? Then use the default.*/ |
||
Line 1,322: | Line 1,864: | ||
end /*j*/ |
end /*j*/ |
||
/*stick a fork in it, we're all done. */ |
/*stick a fork in it, we're all done. */ |
||
say copies('─', 30) finds " words found having " many ' ' copies(char, many) " letters."</ |
say copies('─', 30) finds " words found having " many ' ' copies(char, many) " letters."</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,346: | Line 1,888: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
Line 1,387: | Line 1,929: | ||
see "done..." + nl |
see "done..." + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,409: | Line 1,951: | ||
16. tennessee |
16. tennessee |
||
done... |
done... |
||
</pre> |
|||
=={{header|RPL}}== |
|||
As RPL is a language for calculators, it is not suitable for reading large text files. |
|||
« → w |
|||
« { 5 } 0 CON |
|||
1 w SIZE '''FOR''' j |
|||
w j DUP SUB |
|||
'''IF''' "AEIOUaeiou" SWAP POS '''THEN''' |
|||
LASTARG 1 - 5 MOD 1 + |
|||
DUP2 GET 1 + PUT |
|||
'''END''' |
|||
'''NEXT''' |
|||
DUP 2 GET 3 ≥ SWAP |
|||
[ 1 0 1 1 1 ] DOT NOT AND |
|||
» » ‘<span style="color:blue>EEE?</span>’ STO |
|||
"Seventeen" <span style="color:blue>EEE?</span> <span style="color:grey>@ returns 1 (true)</span> |
|||
"Eighteen" <span style="color:blue>EEE?</span> <span style="color:grey>@ returns 0 (false)</span> |
|||
=={{header|Ruby}}== |
|||
<syntaxhighlight lang="ruby">File.new("unixdict.txt").each do |word| |
|||
puts word if word.count("e") > 3 && word.count("aiou") == 0 |
|||
end |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee |
|||
</pre> |
|||
=={{header|sed}}== |
|||
<syntaxhighlight lang="sed">#!/bin/sed -f |
|||
/^\([^aeiou]*e\)\{4\}[^aiou]*$/!d</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee |
|||
</pre> |
</pre> |
||
=={{header|Snobol}}== |
=={{header|Snobol}}== |
||
< |
<syntaxhighlight lang="snobol"> input(.words, 1,, 'unixdict.txt') :s(line) |
||
output = 'Error!' :(end) |
output = 'Error!' :(end) |
||
line word = words :f(end) |
line word = words :f(end) |
||
Line 1,418: | Line 2,026: | ||
word 'e' arb 'e' arb 'e' arb 'e' :f(line) |
word 'e' arb 'e' arb 'e' arb 'e' :f(line) |
||
output = word :(line) |
output = word :(line) |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,440: | Line 2,048: | ||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">import Foundation |
||
func e3(_ word: String) -> Bool { |
func e3(_ word: String) -> Bool { |
||
Line 1,465: | Line 2,073: | ||
} catch { |
} catch { |
||
print(error.localizedDescription) |
print(error.localizedDescription) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,489: | Line 2,097: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="wren">import "io" for File |
||
import "/fmt" for Fmt |
import "./fmt" for Fmt |
||
var hasAIOU = Fn.new { |word| word.any { |c| "aiou".contains(c) } } |
var hasAIOU = Fn.new { |word| word.any { |c| "aiou".contains(c) } } |
||
Line 1,501: | Line 2,109: | ||
Fmt.print("$2d: $s", count, word) |
Fmt.print("$2d: $s", count, word) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,521: | Line 2,129: | ||
15: telemeter |
15: telemeter |
||
16: tennessee |
16: tennessee |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang="xpl0">string 0; \Use zero-terminated strings |
|||
int I, Ch, Len; |
|||
char Word(100); \(longest word in unixdict.txt is 22 chars) |
|||
def LF=$0A, CR=$0D, EOF=$1A; |
|||
func Vowel(Ch); \Return 'true' if character is a vowel, except "e" |
|||
int Ch; |
|||
case Ch of ^a, ^i, ^o, ^u: return true |
|||
other return false; |
|||
func Es; |
|||
\Return 'true' if Word contains more than 3 e's and no other vowels |
|||
int Cnt, I; |
|||
[Cnt:= 0; |
|||
for I:= 0 to Len-1 do |
|||
[if Word(I) = ^e then Cnt:= Cnt+1; |
|||
if Vowel(Word(I)) then return false; |
|||
]; |
|||
return Cnt > 3; |
|||
]; |
|||
[FSet(FOpen("unixdict.txt", 0), ^I); \open dictionary and set it to device 3 |
|||
OpenI(3); |
|||
repeat I:= 0; |
|||
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR |
|||
if Ch=LF or Ch=EOF then quit; |
|||
Word(I):= Ch; |
|||
I:= I+1; |
|||
]; |
|||
Len:= I; |
|||
Word(I):= 0; \terminate string |
|||
if Es then [Text(0, Word); CrLf(0)]; |
|||
until Ch = EOF; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
belvedere |
|||
dereference |
|||
elsewhere |
|||
erlenmeyer |
|||
evergreen |
|||
everywhere |
|||
exegete |
|||
freewheel |
|||
nevertheless |
|||
persevere |
|||
preference |
|||
referee |
|||
seventeen |
|||
seventeenth |
|||
telemeter |
|||
tennessee |
|||
</pre> |
</pre> |
Latest revision as of 06:20, 3 July 2024
- 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
- Count how many vowels and consonants occur in a string
- Remove/replace
- XXXX redacted
- Conjugate a Latin verb
- Remove vowels from a string
- String interpolation (included)
- 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
- Sattolo cycle
- Knuth shuffle
- Ordered words
- Superpermutation minimisation
- Textonyms (using a phone text pad)
- Anagrams
- Anagrams/Deranged anagrams
- Permutations/Derangements
- Find/Search/Determine
- ABC words
- Odd words
- Word ladder
- Semordnilap
- Word search
- Wordiff (game)
- String matching
- Tea cup rim text
- Alternade words
- Changeable words
- State name puzzle
- String comparison
- Unique characters
- Unique characters in each string
- Extract file extension
- Levenshtein distance
- Palindrome detection
- Common list elements
- Longest common suffix
- Longest common prefix
- Compare a list of strings
- 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
- Sum of the digits of n is substring of n
- 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
- Longest substrings without repeating 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
- Substring
- Rep-string
- Word wrap
- 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
- Mad Libs
- Magic 8-ball
- 99 Bottles of Beer
- The Name Game (a song)
- The Old lady swallowed a fly
- The Twelve Days of Christmas
- Tokenize
- Text between
- Tokenize a string
- Word break problem
- Tokenize a string with escaping
- Split a character string based on change of character
- Sequences
11l
V aiou = ‘aiou’ // to get round ‘bug in MSVC 2017’[https://developercommunity.visualstudio.com/t/bug-with-operator-in-c/565417]
L(word) File(‘unixdict.txt’).read().split("\n")
I !any(word.map(c -> c C :aiou)) & sum(word.map(c -> Int(c == ‘e’))) > 3
print(word)
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
8080 Assembly
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
Action!
In the following solution the input file unixdict.txt is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used.
BYTE FUNC Count(CHAR ARRAY text CHAR c)
BYTE i,n
i=1 n=0
FOR i=1 TO text(0)
DO
IF text(i)=c THEN
n==+1
FI
OD
RETURN (n)
BYTE FUNC IsValidWord(CHAR ARRAY word)
IF Count(word,'a)#0 THEN RETURN(0) FI
IF Count(word,'e)<=3 THEN RETURN(0) FI
IF Count(word,'i)#0 THEN RETURN(0) FI
IF Count(word,'o)#0 THEN RETURN(0) FI
IF Count(word,'u)#0 THEN RETURN(0) FI
RETURN (1)
PROC FindWords(CHAR ARRAY fname)
CHAR ARRAY line(256)
CHAR ARRAY tmp(256)
BYTE dev=[1]
Close(dev)
Open(dev,fname,4)
WHILE Eof(dev)=0
DO
InputSD(dev,line)
IF IsValidWord(line) THEN
PrintE(line)
FI
OD
Close(dev)
RETURN
PROC Main()
CHAR ARRAY fname="H6:UNIXDICT.TXT"
FindWords(fname)
RETURN
- Output:
Screenshot from Atari 8-bit computer
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Ada
with Ada.Text_Io;
with Ada.Strings.Maps;
with Ada.Strings.Fixed;
procedure Find_Three_E is
use Ada.Text_Io;
use Ada.Strings;
use type Ada.Strings.Maps.Character_Set;
Filename : constant String := "unixdict.txt";
Y_Is_Vowel : constant Boolean := False;
Set_E : constant Maps.Character_Set := Maps.To_Set ("eE");
Set_Y : constant Maps.Character_Set := Maps.To_Set ("yY");
Set_Others : constant Maps.Character_Set :=
Maps.To_Set ("aiouAIOU") or (if Y_Is_Vowel then Set_Y else Maps.Null_Set);
File : File_Type;
begin
Open (File, In_File, Filename);
while not End_Of_File (File) loop
declare
Word : constant String := Get_Line (File);
Count_E : constant Natural := Fixed.Count (Word, Set_E);
Count_Others : constant Natural := Fixed.Count (Word, Set_Others);
begin
if Count_E > 3 and Count_Others = 0 then
Put_Line (Word);
end if;
end;
end loop;
Close (File);
end Find_Three_E;
ALGOL 68
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)
AppleScript
on findWordsWhichContainsMoreThan3EVowels()
script o
property wrds : words of ¬
(read file ((path to desktop as text) & "unixdict.txt") as «class utf8»)
end script
set output to {}
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "e"
repeat with thisWord in o's wrds
set thisWord to thisWord's contents
if (((count thisWord's text items) > 4) and not ¬
((thisWord contains "a") or (thisWord contains "i") or ¬
(thisWord contains "o") or (thisWord contains "u"))) then
set end of output to thisWord
end if
end repeat
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
return output
end findWordsWhichContainsMoreThan3EVowels
findWordsWhichContainsMoreThan3EVowels()
- Output:
"belvedere
dereference
elsewhere
erlenmeyer
evergreen
everywhere
exegete
freewheel
nevertheless
persevere
preference
referee
seventeen
seventeenth
telemeter
tennessee"
Arturo
words: read.lines relative "unixdict.txt"
otherVowels: ["a" "i" "o" "u"]
containsMoreThan3Es?: function [w][
if 4 > size match w "e" -> return false
loop otherVowels 'v [
if contains? w v -> return false
]
return true
]
loop words 'word [
if containsMoreThan3Es? word ->
print word
]
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
AutoHotkey
FileRead, db, % A_Desktop "\unixdict.txt"
vowelsLessE := ["a", "i", "o", "u"]
oRes := []
main:
for i, word in StrSplit(db, "`n", "`r")
{
for j, v in vowelsLessE
{
StrReplace(word, v, v, c)
if c
continue main
}
StrReplace(word, "e", "e", c)
if c > 3
result .= word "`n"
}
MsgBox, 262144, , % result
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
AWK
/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
BCPL
get "libhdr"
let reads(v) = valof
$( v%0 := 0
$( let ch = rdch()
if ch = endstreamch resultis false
if ch = '*N' resultis true
v%0 := v%0 + 1
v%(v%0) := ch
$) repeat
$)
let testword(v) = valof
$( let e = 0
for i = 1 to v%0
$( if v%i='e' then e := e+1
if v%i='a' | v%i='i' | v%i='u' | v%i='o' resultis false
$)
resultis e > 3
$)
let start() be
$( let word = vec 256/BYTESPERWORD
selectinput(findinput("unixdict.txt"))
while reads(word) if testword(word) do writef("%S*N",word)
endread()
$)
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
C
#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
C++
#include <iostream>
#include <fstream>
bool test(const std::string &line) {
unsigned int e = 0;
for (char c : line) {
switch(std::tolower(c)) {
case 'a': return false;
case 'i': return false;
case 'o': return false;
case 'u': return false;
case 'e': ++e;
}
}
return e > 3;
}
int main() {
std::ifstream dict{"unixdict.txt"};
if (! dict.is_open()) {
std::cerr << "Cannot open unixdict.txt\n";
return 3;
}
for (std::string line; std::getline(dict, line);) {
if (test(line)) std::cout << line << std::endl;
}
return 0;
}
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
CLU
e_word = proc (s: string) returns (bool)
e: int := 0
for c: char in string$chars(s) do
if string$indexc(c, "aiou") ~= 0 then
return (false)
end
if c = 'e' then e := e + 1 end
end
return (e > 3)
end e_word
start_up = proc ()
po: stream := stream$primary_output()
dict: stream := stream$open(file_name$parse("unixdict.txt"), "read")
while true do
word: string := stream$getl(dict)
except when end_of_file: break end
if e_word(word) then stream$putl(po, word) end
end
stream$close(dict)
end start_up
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. E-WORDS.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DICT ASSIGN TO DISK
ORGANIZATION LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD DICT
LABEL RECORD STANDARD
VALUE OF FILE-ID IS "unixdict.txt".
01 WORD PIC X(64).
WORKING-STORAGE SECTION.
01 E PIC 99.
01 OTHER PIC 99.
PROCEDURE DIVISION.
BEGIN.
OPEN INPUT DICT.
READ-WORD.
READ DICT, AT END CLOSE DICT, STOP RUN.
PERFORM CHECK-WORD.
GO TO READ-WORD.
CHECK-WORD.
MOVE ZERO TO E, OTHER.
INSPECT WORD TALLYING OTHER FOR ALL 'a'.
INSPECT WORD TALLYING E FOR ALL 'e'.
INSPECT WORD TALLYING OTHER FOR ALL 'i'.
INSPECT WORD TALLYING OTHER FOR ALL 'o'.
INSPECT WORD TALLYING OTHER FOR ALL 'u'.
IF E IS GREATER THAN 3 AND OTHER IS EQUAL TO ZERO,
DISPLAY WORD.
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Cowgol
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
Delphi
This program makes extensive use of the standard Delphi TStringList component. It holds the dictionary, which is preloaded. It capture the E-Vowel-only information in a TStringList and uses it to display the words.
var Dict: TStringList; {List holds dictionary}
function HasEVowels(S: string): boolean;
{Test if string has exclusively E-Vowels and no "a,i,o,u"}
var I,ECount: integer;
begin
Result:=False;
ECount:=0;
for I:=1 to Length(S) do
begin
if S[I] in ['a','i','o','u'] then exit;
if S[I]='e' then Inc(ECount);
end;
Result:=ECount>3;
end;
procedure ShowEVowels(Memo: TMemo);
{Show words in dictionary that only}
{have e-vowels and have at least three}
var I: integer;
var SL: TStringList;
var S: string;
begin
SL:=TStringList.Create;
try
{Make list of words with least three E-vowels}
for I:=0 to Dict.Count-1 do
if HasEVowels(Dict[I]) then SL.Add(Dict[I]);
{Display all the words found}
S:='Found: '+IntToStr(SL.Count)+#$0D#$0A;
for I:=0 to SL.Count-1 do
begin
S:=S+Format('%-23s',[SL[I]]);
if (I mod 4)=3 then S:=S+#$0D#$0A;
end;
Memo.Text:=S;
finally SL.Free; end;
end;
initialization
{Create/load dictionary}
Dict:=TStringList.Create;
Dict.LoadFromFile('unixdict.txt');
Dict.Sorted:=True;
finalization
Dict.Free;
end.
- Output:
Found: 16 belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Draco
proc eword(*char line) bool:
word e;
char c;
bool ok;
ok := true;
e := 0;
while
c := line*;
line := line + 1;
ok and c ~= '\e'
do
if c='a' or c='i' or c='o' or c='u' then
ok := false
elif c='e' then
e := e + 1
fi
od;
ok and e>3
corp
proc nonrec main() void:
file(1024) dictfile;
[32] char buf;
*char line;
channel input text dict;
open(dict, dictfile, "unixdict.txt");
line := &buf[0];
while readln(dict; line) do
if eword(line) then writeln(line) fi
od;
close(dict)
corp
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
ed
First remove the short lines, then remove the ones without "the".
# by Artyom Bologov
H
# Remove the words with letters other than e
g/[aiou]/d
# Remove the words without three e's
v/.*e.*e.*e.*e.*/d
,p
Q
- Output:
$ ed -s unixdict.txt < e-vowels.ed belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
F#
// 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
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
Forth
: e3 ( addr u -- ? )
0 { ecount }
0 do
dup c@ case
'a' of false endof
'e' of ecount 1+ to ecount true endof
'i' of false endof
'o' of false endof
'u' of false endof
true swap
endcase
invert if unloop drop false exit then
1+
loop
drop
ecount 3 > ;
256 constant max-line
: main
0 0 { count fd-in }
s" unixdict.txt" r/o open-file throw to fd-in
begin
here max-line fd-in read-line throw
while
here swap 2dup e3 if
count 1+ to count
count 2 .r ." . " type cr
else
2drop
then
repeat
drop
fd-in close-file throw ;
main
bye
- 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
FreeBASIC
open "unixdict.txt" for input as #1
dim as string s, c
dim as integer e, i
while not eof(1)
line input #1, s
e = 0
for i = 1 to len(s)
c = mid(s,i,1)
if c="e" then e+=1
if c="a" or c="i" or c="o" or c="u" then continue while
next i
if e>3 then print s
wend
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Frink
for word = lines["https://web.archive.org/web/20180611003215if_/http://www.puzzlers.org:80/pub/wordlists/unixdict.txt"]
{
d = countToDict[charList[word]]
if d.get["a",0] == 0 and d.get["e",0] > 3 and d.get["i",0] == 0 and d.get["o",0] == 0 and d.get["u",0] == 0
println[word]
}
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
FutureBasic
include resources "unixdict.txt"
local fn ThreePlusEWord( string as CFStringRef ) as BOOL
long i, count = len(string), ecount = 0
for i = 0 to count -1
unichar ch = fn StringCharacterAtIndex( string, i )
select (ch)
case _"a", _"A", _"i", _"I", _"o", _"O", _"u", _"U" : exit fn = NO
case _"e", _"E" : ecount++
case else : continue
end select
next
if ecount > 3 then exit fn = YES
end fn = NO
void local fn CheckWords
CFURLRef url = fn BundleURLForResource( fn BundleMain, @"unixdict", @"txt", NULL )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
CFArrayRef words = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
CFMutableStringRef mutStr = fn MutableStringNew
NSUInteger count = 1
CFStringRef wordStr
for wordStr in words
if fn ThreePlusEWord( wordStr ) then MutableStringAppendString( mutStr, fn StringWithFormat( @"%2lu. %@\n", count, wordStr ) ) : count++
next
print mutStr
end fn
fn CheckWords
HandleEvents
- 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
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
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
Or, defining the predicate in terms of a single fold:
import System.IO (readFile)
import Data.Bifunctor (first)
---------- MORE THAN THREE VOWELS, AND NONE BUT E --------
p :: String -> Bool
p = uncurry (&&) . first (3 <) . foldr rule (0, True)
rule :: Char -> (Int, Bool) -> (Int, Bool)
rule _ (n, False) = (n, False)
rule 'e' (n, b) = (succ n, b)
rule c (n, b)
| c `elem` "aiou" = (n, False)
| otherwise = (n, b)
--------------------------- TEST -------------------------
main :: IO ()
main = readFile "unixdict.txt"
>>= (putStrLn . unlines . filter p . lines)
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
J
>(#~ (0 4 0 0 0 -: 4 <. +/ .(=/)&'aeiou')@>) cutLF fread'unixdict.txt'
belvedere
dereference
elsewhere
erlenmeyer
evergreen
everywhere
exegete
freewheel
nevertheless
persevere
preference
referee
seventeen
seventeenth
telemeter
tennessee
(Also possible to do this with regular expressions, but this works. Here, we counted how many times each vowel occurred, limited the maximum count to 4, and checked the resulting signature.)
JavaScript
ECMAScript defines no file operations. Here, to read the dictionary, we use a library available to Apple's "JavaScript for Automation" embedding of a JS interpreter.
(() => {
"use strict";
// ----- MORE THAN THREE VOWELS, AND NONE BUT E ------
// p :: String -> Bool
const p = w => {
// True if the word contains more than three vowels,
// and none of its vowels are other than "e".
const
[noOtherVowels, eCount] = [...w].reduce(
([bool, n], c) => bool
? "e" === c
? [bool, 1 + n]
: "aiou".includes(c)
? [false, n]
: [bool, n]
: [false, n],
// Initial accumulator.
[true, 0]
);
return noOtherVowels && (3 < eCount);
};
// ---------------------- TEST -----------------------
const main = () =>
lines(
readFile(
"~/Desktop/unixdict.txt"
)
)
.filter(p)
.join("\n");
// --------------------- GENERIC ---------------------
// lines :: String -> [String]
const lines = s =>
// A list of strings derived from a single string
// which is delimited by \n or by \r\n or \r.
0 < s.length
? s.split(/\r\n|\n|\r/u)
: [];
// ----------------------- jxa -----------------------
// readFile :: FilePath -> IO String
const readFile = fp => {
// The contents of a text file at the
// given file path.
const
e = $(),
ns = $.NSString
.stringWithContentsOfFileEncodingError(
$(fp).stringByStandardizingPath,
$.NSUTF8StringEncoding,
e
);
return ObjC.unwrap(
ns.isNil() ? (
e.localizedDescription
) : ns
);
};
// MAIN ---
return main();
})();
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
jq
Works with gojq, the Go implementation of jq
Using regular expressions
inputs
| select(test("[aiou]")|not)
| select(test("e.*e.*e.*e"))
Regex-free solution
def count(s): reduce s as $x (null; .+1);
("aiou" | explode) as $disallow
| inputs
| . as $word
| explode
| select( all(.[]; . != $disallow[]) and
count(.[] | select(. == 101)) > 3) # "e" is 101
| $word
- Output:
Invocation example: jq -nrR program.jq unixdict.txt
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Julia
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
Kotlin
import kotlin.io.path.Path
import kotlin.io.path.useLines
fun main() {
Path("unixdict.txt").useLines { lines ->
lines
.filter { line -> line.none { it in "aiou" } }
.filter { line -> line.count { it == 'e' } > 3 }
.forEach(::println)
}
}
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Ksh
#!/bin/ksh
# Find words which contains more than 3 e vowels and only e vowels
# # Variables:
#
badvowels='a|i|o|u'
typeset -si MINE=4
dictionary='../unixdict.txt'
# # Functions:
#
# # Function _countch(str, ch) return cpount of ch in str
#
function _countch {
typeset _str ; typeset -l _str="$1"
typeset _ch ; typeset -lL1 _ch="$2"
typeset _i _cnt ; typeset -si _i _cnt=0
for ((_i=0; _i<${#_str}; _i++)); do
[[ ${_str:_i:1} == ${_ch} ]] && (( _cnt++ ))
done
echo ${_cnt}
}
######
# main #
######
while read; do
[[ $REPLY == *+(${badvowels})* ]] && continue
(( $(_countch "$REPLY" "e") >= MINE )) && print $REPLY
done < ${dictionary}
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter
tennessee
Mathematica/Wolfram Language
vowels = Characters["euioa"];
dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dict //= StringSplit[#, "\n"] &;
dict = {#, Select[Characters[#], MemberQ[vowels, #] &]} & /@ dict;
dict //= Select[Last /* Count["e"] /* GreaterThan[3]];
dict //= Select[Last /* Apply[SameQ]];
dict[[All, 1]]
- Output:
{belvedere, dereference, elsewhere, erlenmeyer, evergreen, everywhere, exegete, freewheel, nevertheless, persevere, preference, referee, seventeen, seventeenth, telemeter, tennessee}
Nim
import strutils
const NonEVowels = ['a', 'i', 'o', 'u']
var count = 0
for word in "unixdict.txt".lines:
block checkWord:
if word.count('e') <= 3: break checkWord
for vowel in NonEVowels:
if vowel in word: break checkWord
inc count
stdout.write word.align(14), if count mod 4 == 0: '\n' else: ' '
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Pascal
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
#!/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
with javascript_semantics function note(string word) return find_any("aiou",word)=0 and length(find_all('e',word))>3 end function sequence notes = filter(unix_dict(),note) printf(1,"%d words: %s\n",{length(notes),join(shorten(notes,"",3))})
- Output:
16 words: belvedere dereference elsewhere ... seventeenth telemeter tennessee
PL/I
moreThanThreeEs: procedure options(main);
declare dict file;
open file(dict) title('unixdict.txt');
on endfile(dict) stop;
declare word char(32) varying;
do while('1'b);
next: get file(dict) list(word);
declare (e, i) fixed, ch char;
e = 0;
do i=1 to length(word);
ch = substr(word, i, 1);
if verify(ch, 'aiou') = 0 then go to next;
if ch = 'e' then e = e + 1;
end;
if e > 3 then put skip list(word);
end;
close file(dict);
end moreThanThreeEs;
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Python
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
Quackery
[ bit
[ 0 $ "aiou"
witheach
[ bit | ] ] constant
& 0 != ] is aiou ( c --> b )
[]
$ "rosetta/unixdict.txt" sharefile drop nest$
witheach
[ 0 over
witheach
[ dup char e = if
[ dip 1+ ]
aiou if
[ drop 0
conclude ] ]
3 > iff
[ nested join ]
else drop ]
50 wrap$
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
R
Adapting this from https://rosettacode.org/wiki/Find_words_which_contains_all_the_vowels#R is trivial.
dict <- scan("https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt", what = character())
#The following line is equivalent to sapply(c("a", "i", "o", "u"), function(x) stringr::str_count(dict, x))
#As with all things with strings in R, life is easier with stringr or stringi.
notEVowelCount <- sapply(c("a", "i", "o", "u"), function(x) lengths(regmatches(dict, gregexec(x, dict))))
eCount <- lengths(regmatches(dict, gregexec("e", dict)))
dict[apply(notEVowelCount, MARGIN = 1, function(x) all(x < 1)) & eCount > 3]
Racket
#lang racket
;; probably not the best name, but matches the name of the task
(define (contains-more-than-3-e-vowels? s)
(let loop ((i (string-length s)) (es 0))
(if (zero? i)
(> es 3)
(let ((i- (sub1 i)))
(match (string-ref s i-)
((or #\a #\i #\o #\u) #f)
(#\e (loop i- (add1 es)))
(_ (loop i- es)))))))
(define qualifying-words
(filter contains-more-than-3-e-vowels?
(file->lines "../../data/unixdict.txt")))
(module+ main
qualifying-words)
- Output:
'("belvedere" "dereference" "elsewhere" "erlenmeyer" "evergreen" "everywhere" "exegete" "freewheel" "nevertheless" "persevere" "preference" "referee" "seventeen" "seventeenth" "telemeter" "tennessee")
Raku
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â
Red
Red[]
words: read/lines %unixdict.txt
forbidden: charset "aiou"
foreach word words [
e's: 0
retain: yes
foreach char word [
if find forbidden char [retain: no break]
if #"e" = char [e's: e's + 1]
]
if all [retain e's > 3] [print word]
]
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
REXX
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
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...
RPL
As RPL is a language for calculators, it is not suitable for reading large text files.
« → w
« { 5 } 0 CON
1 w SIZE FOR j
w j DUP SUB
IF "AEIOUaeiou" SWAP POS THEN
LASTARG 1 - 5 MOD 1 +
DUP2 GET 1 + PUT
END
NEXT
DUP 2 GET 3 ≥ SWAP
[ 1 0 1 1 1 ] DOT NOT AND
» » ‘EEE?’ STO
"Seventeen" EEE? @ returns 1 (true) "Eighteen" EEE? @ returns 0 (false)
Ruby
File.new("unixdict.txt").each do |word|
puts word if word.count("e") > 3 && word.count("aiou") == 0
end
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
sed
#!/bin/sed -f
/^\([^aeiou]*e\)\{4\}[^aiou]*$/!d
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Snobol
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
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
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
XPL0
string 0; \Use zero-terminated strings
int I, Ch, Len;
char Word(100); \(longest word in unixdict.txt is 22 chars)
def LF=$0A, CR=$0D, EOF=$1A;
func Vowel(Ch); \Return 'true' if character is a vowel, except "e"
int Ch;
case Ch of ^a, ^i, ^o, ^u: return true
other return false;
func Es;
\Return 'true' if Word contains more than 3 e's and no other vowels
int Cnt, I;
[Cnt:= 0;
for I:= 0 to Len-1 do
[if Word(I) = ^e then Cnt:= Cnt+1;
if Vowel(Word(I)) then return false;
];
return Cnt > 3;
];
[FSet(FOpen("unixdict.txt", 0), ^I); \open dictionary and set it to device 3
OpenI(3);
repeat I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
Len:= I;
Word(I):= 0; \terminate string
if Es then [Text(0, Word); CrLf(0)];
until Ch = EOF;
]
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
- Draft Programming Tasks
- 11l
- 8080 Assembly
- Action!
- Ada
- ALGOL 68
- AppleScript
- Arturo
- AutoHotkey
- AWK
- BCPL
- C
- C++
- CLU
- COBOL
- Cowgol
- Delphi
- Classes,StdCtrls,SysUtils
- Draco
- Ed
- F Sharp
- Factor
- Forth
- FreeBASIC
- Frink
- FutureBasic
- Go
- Haskell
- J
- JavaScript
- Jq
- Julia
- Kotlin
- Ksh
- Mathematica
- Wolfram Language
- Nim
- Pascal
- Perl
- Phix
- PL/I
- Python
- Quackery
- R
- Racket
- Raku
- Red
- REXX
- Ring
- RPL
- Ruby
- Sed
- Snobol
- Swift
- Wren
- Wren-fmt
- XPL0