Find words which contains more than 3 e vowels: Difference between revisions
Find words which contains more than 3 e vowels (view source)
Revision as of 13:05, 27 August 2022
, 1 year agosyntax highlighting fixup automation
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 15:
{{trans|Python}}
<
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)</
{{out}}
Line 42:
=={{header|8080 Assembly}}==
<
fopen: equ 15 ; Open file
fread: equ 20 ; Read block
Line 105:
jmp 5
emsg: db 'Error$'
word: equ $</
{{out}}
Line 130:
=={{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.
<
BYTE i,n
Line 171:
FindWords(fname)
RETURN</
{{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]
Line 180:
=={{header|Ada}}==
<
with Ada.Strings.Maps;
with Ada.Strings.Fixed;
Line 210:
end loop;
Close (File);
end Find_Three_E;</
=={{header|ALGOL 68}}==
Interesting to note the word with the most es is "dereference" - a term first used (I believe) in Algol 68...
<
# read the list of words and look for suitable words #
Line 259:
OD;
close( input file )
FI</
{{out}}
<pre>
Line 282:
=={{header|Arturo}}==
<
otherVowels: ["a" "i" "o" "u"]
containsMoreThan3Es?: function [w][
Line 296:
if containsMoreThan3Es? word ->
print word
]</
{{out}}
Line 318:
=={{header|AutoHotkey}}==
<
vowelsLessE := ["a", "i", "o", "u"]
oRes := []
Line 334:
result .= word "`n"
}
MsgBox, 262144, , % result</
{{out}}
<pre>belvedere
Line 354:
=={{header|AWK}}==
<
{{out}}
Line 378:
=={{header|BCPL}}==
<
let reads(v) = valof
Line 404:
while reads(word) if testword(word) do writef("%S*N",word)
endread()
$)</
{{out}}
<pre>belvedere
Line 424:
=={{header|C}}==
<
#define SIZE 256
Line 458:
fclose(f);
return 0;
}</
{{out}}
Line 480:
=={{header|C++}}==
<
#include <fstream>
Line 510:
return 0;
}</
{{out}}
Line 532:
=={{header|CLU}}==
<
e: int := 0
for c: char in string$chars(s) do
Line 554:
end
stream$close(dict)
end start_up</
{{out}}
<pre>belvedere
Line 574:
=={{header|COBOL}}==
<
PROGRAM-ID. E-WORDS.
Line 611:
INSPECT WORD TALLYING OTHER FOR ALL 'u'.
IF E IS GREATER THAN 3 AND OTHER IS EQUAL TO ZERO,
DISPLAY WORD.</
{{out}}
<pre>belvedere
Line 631:
=={{header|Cowgol}}==
<
include "file.coh";
Line 679:
end if;
ForEachLine(&file, CheckWord);</
{{out}}
Line 702:
=={{header|Draco}}==
<
word e;
char c;
Line 736:
close(dict)
corp</
{{out}}
<pre>belvedere
Line 756:
=={{header|F_Sharp|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")
</syntaxhighlight>
{{out}}
<pre>
Line 782:
=={{header|Factor}}==
<
sequences ;
Line 788:
[ [ "aiou" member? ] any? ] reject
[ [ CHAR: e = ] count 3 > ] filter
[ 1 + "%2d: " printf print ] each-index</
{{out}}
<pre>
Line 811:
=={{header|Forth}}==
{{works with|Gforth}}
<
0 { ecount }
0 do
Line 847:
main
bye</
{{out}}
Line 870:
=={{header|FreeBASIC}}==
<
dim as string s, c
Line 884:
next i
if e>3 then print s
wend</
{{out}}<pre>
belvedere
Line 905:
=={{header|Frink}}==
<
{
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]
}</
{{out}}
<pre>
Line 932:
=={{header|Go}}==
<
import (
Line 976:
}
}
}</
{{out}}
Line 999:
=={{header|Haskell}}==
<
main = withFile "unixdict.txt" ReadMode $ \h -> do
Line 1,005:
putStrLn $ unlines $ filter valid words
valid w = not (any (`elem` "aiou") w) && length (filter (=='e') w) > 3</
{{out}}
Line 1,028:
=={{header|J}}==
<
belvedere
dereference
Line 1,044:
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.)
Line 1,053:
===Using regular expressions===
<
| select(test("[aiou]")|not)
| select(test("e.*e.*e.*e"))</
===Regex-free solution===
<
("aiou" | explode) as $disallow
Line 1,066:
count(.[] | select(. == 101)) > 3) # "e" is 101
| $word
</syntaxhighlight>
{{out}}
Invocation example: jq -nrR program.jq unixdict.txt
Line 1,090:
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<
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)
</
<pre>
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel
Line 1,102:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 1,138:
(( $(_countch "$REPLY" "e") >= MINE )) && print $REPLY
done < ${dictionary}
</syntaxhighlight>
{{out}}<pre>
belvedere
Line 1,158:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dict //= StringSplit[#, "\n"] &;
Line 1,164:
dict //= Select[Last /* Count["e"] /* GreaterThan[3]];
dict //= Select[Last /* Apply[SameQ]];
dict[[All, 1]]</
{{out}}
<pre>{belvedere, dereference, elsewhere, erlenmeyer, evergreen, everywhere, exegete, freewheel, nevertheless, persevere, preference, referee, seventeen, seventeenth, telemeter, tennessee}</pre>
=={{header|Nim}}==
<
const NonEVowels = ['a', 'i', 'o', 'u']
Line 1,180:
if vowel in word: break checkWord
inc count
stdout.write word.align(14), if count mod 4 == 0: '\n' else: ' '</
{{out}}
Line 1,190:
=={{header|Pascal}}==
{{works with|Turbo Pascal}}
<
var
FileVar: Text;
Line 1,217:
end
end
end.</
{{out}}
Line 1,239:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Find_words_which_contains_more_than_3_e_vowels
Line 1,245:
@ARGV = 'unixdict.txt';
tr/e// > 3 and tr/aiou// == 0 and print while <>;</
{{out}}
belvedere
Line 1,265:
=={{header|Phix}}==
<!--<
<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: #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>
<!--</
{{out}}
<pre>
Line 1,277:
=={{header|PL/I}}==
<
declare dict file;
open file(dict) title('unixdict.txt');
Line 1,298:
close file(dict);
end moreThanThreeEs;</
{{out}}
<pre>belvedere
Line 1,318:
=={{header|Python}}==
<
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())</
{{out}}
Line 1,344:
=={{header|R}}==
Adapting this from https://rosettacode.org/wiki/Find_words_which_contains_all_the_vowels#R is trivial.
<
#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]</
=={{header|Racket}}==
<
;; probably not the best name, but matches the name of the task
Line 1,371:
(module+ main
qualifying-words)</
{{out}}
Line 1,380:
Hardly even worth saving as a script file; an easily entered one-liner.
<syntaxhighlight lang="raku"
{{out}}
<pre>
Line 1,403:
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.
<syntaxhighlight lang="raku"
.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 [https://github.com/thundergnat/rc-run/blob/master/rc/resources/lemiz.txt Les Misérables file] used for the [[Word frequency]] task?
Line 1,419:
=={{header|Red}}==
<
words: read/lines %unixdict.txt
Line 1,432:
]
if all [retain e's > 3] [print word]
]</
{{out}}
<pre>
Line 1,458:
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.
<
parse arg char many iFID . /*obtain optional arguments from the CL*/
if char=='' | char=="," then char= 'e' /*Not specified? Then use the default.*/
Line 1,482:
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─', 30) finds " words found having " many ' ' copies(char, many) " letters."</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,506:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,547:
see "done..." + nl
</syntaxhighlight>
Output:
<pre>
Line 1,572:
=={{header|Ruby}}==
<
puts word if word.count("e") > 3 && word.count("aiou") == 0
end
</syntaxhighlight>
{{out}}
<pre>belvedere
Line 1,595:
</pre>
=={{header|Snobol}}==
<
output = 'Error!' :(end)
line word = words :f(end)
Line 1,601:
word 'e' arb 'e' arb 'e' arb 'e' :f(line)
output = word :(line)
end</
{{out}}
Line 1,623:
=={{header|Swift}}==
<
func e3(_ word: String) -> Bool {
Line 1,648:
} catch {
print(error.localizedDescription)
}</
{{out}}
Line 1,672:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
import "/fmt" for Fmt
Line 1,684:
Fmt.print("$2d: $s", count, word)
}
}</
{{out}}
Line 1,707:
=={{header|XPL0}}==
<
int I, Ch, Len;
char Word(100); \(longest word in unixdict.txt is 22 chars)
Line 1,740:
if Es then [Text(0, Word); CrLf(0)];
until Ch = EOF;
]</
{{out}}
|