Find words which contains all the vowels
Use the dictionary unixdict.txt
- Task
Find the words which contains all the vowels, but each vowel should appear only once in a word.
The length of any word shown should have a length > 10.
- 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
Ada
<lang Ada>with Ada.Text_Io; with Ada.Strings.Maps; with Ada.Strings.Fixed;
procedure Find_All_Vowels is
use Ada.Text_Io; use Ada.Strings;
type Vowels is ('a', 'e', 'i', 'o', 'u'); type Count_Type is array (Vowels) of Natural;
Filename : constant String := "unixdict.txt"; Chars : constant array (Vowels) of Character := "aeiou"; File : File_Type;
begin
Open (File, In_File, Filename); while not End_Of_File (File) loop declare Word : constant String := Get_Line (File); Count : Count_Type; begin for Vowel in Vowels loop Count (Vowel) := Fixed.Count (Word, Maps.To_Set (Chars (Vowel))); end loop;
if Count = Count_Type'(others => 1) and Word'Length > 10 then Put_Line (Word); end if; end; end loop; Close (File);
end Find_All_Vowels;</lang>
ALGOL 68
<lang algol68># find 11 or more character words that contain all the vowels once #
- 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 vowel words := 0; WHILE STRING word; get( input file, ( word, newline ) ); NOT at eof DO IF ( UPB word - LWB word ) + 1 > 10 THEN # have an eleven or more character word # INT a count := 0, e count := 0, i count := 0, o count := 0, u count := 0; FOR w pos FROM LWB word TO UPB word DO CHAR c = word[ w pos ]; IF c = "a" THEN a count +:= 1 ELIF c = "e" THEN e count +:= 1 ELIF c = "i" THEN i count +:= 1 ELIF c = "o" THEN o count +:= 1 ELIF c = "u" THEN u count +:= 1 FI OD; IF a count = 1 AND e count = 1 AND i count = 1 AND o count = 1 AND u count = 1 THEN vowel words +:= 1; print( ( whole( vowel words, -5 ), ": ", word, newline ) ) FI FI OD; close( input file )
FI</lang>
- Output:
1: ambidextrous 2: bimolecular 3: cauliflower 4: communicable 5: communicate 6: consanguine 7: consultative 8: countervail 9: exclusionary 10: grandiloquent 11: importunate 12: incommutable 13: incomputable 14: insupportable 15: loudspeaking 16: malnourished 17: mensuration 18: oneupmanship 19: pandemonium 20: permutation 21: perturbation 22: portraiture 23: praseodymium 24: stupefaction 25: sulfonamide
AWK
<lang AWK>
- syntax: GAWK -f FIND_WORDS_WHICH_CONTAINS_ALL_THE_VOWELS.AWK unixdict.txt
{ if (length($0) <= 10) {
next } tmp = gsub(/a/,"&",$0) gsub(/e/,"&",$0) gsub(/i/,"&",$0) gsub(/o/,"&",$0) gsub(/u/,"&",$0) if (tmp ~ /^11111$/) { printf("%s\n",$0) }
} END {
exit(0)
} </lang>
- Output:
ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide
C++
<lang cpp>#include <bitset>
- include <cctype>
- include <cstdlib>
- include <fstream>
- include <iomanip>
- include <iostream>
bool contains_all_vowels_once(const std::string& word) {
std::bitset<5> vowels; for (char ch : word) { ch = std::tolower(static_cast<unsigned char>(ch)); size_t bit = 0; switch (ch) { case 'a': bit = 0; break; case 'e': bit = 1; break; case 'i': bit = 2; break; case 'o': bit = 3; break; case 'u': bit = 4; break; default: continue; } if (vowels.test(bit)) return false; vowels.set(bit); } return vowels.all();
}
int main(int argc, char** argv) {
const char* filename(argc < 2 ? "unixdict.txt" : argv[1]); std::ifstream in(filename); if (!in) { std::cerr << "Cannot open file '" << filename << "'.\n"; return EXIT_FAILURE; } std::string word; int n = 0; while (getline(in, word)) { if (word.size() > 10 && contains_all_vowels_once(word)) std::cout << std::setw(2) << ++n << ": " << word << '\n'; } return EXIT_SUCCESS;
}</lang>
- Output:
1: ambidextrous 2: bimolecular 3: cauliflower 4: communicable 5: communicate 6: consanguine 7: consultative 8: countervail 9: exclusionary 10: grandiloquent 11: importunate 12: incommutable 13: incomputable 14: insupportable 15: loudspeaking 16: malnourished 17: mensuration 18: oneupmanship 19: pandemonium 20: permutation 21: perturbation 22: portraiture 23: praseodymium 24: stupefaction 25: sulfonamide
Delphi
<lang Delphi> program Find_words_which_contains_all_the_vowels;
{$APPTYPE CONSOLE}
uses
System.SysUtils, System.IoUtils;
function IsVowelsOnce(w: string): Boolean; const
chars: array[0..4] of char = ('a', 'e', 'i', 'o', 'u');
var
cs: array[0..4] of Boolean; i: Integer; c: char;
begin
if w.IsEmpty then exit(false);
FillChar(cs, length(cs), 0);
for c in w do begin for i := 0 to 4 do begin if c = chars[i] then begin if cs[i] then exit(false); cs[i] := True; end; end; end;
for i := 0 to 4 do if not cs[i] then exit(False); Result := True;
end;
begin
var Lines := TFile.ReadAllLines('unixdict.txt'); var count := 0; for var Line in Lines do if IsVowelsOnce(Line) and (Line.length > 10) then begin inc(count); Writeln(count: 2, ': ', Line); end;
readln;
end.</lang>
- Output:
1: ambidextrous 2: bimolecular 3: cauliflower 4: communicable 5: communicate 6: consanguine 7: consultative 8: countervail 9: exclusionary 10: grandiloquent 11: importunate 12: incommutable 13: incomputable 14: insupportable 15: loudspeaking 16: malnourished 17: mensuration 18: oneupmanship 19: pandemonium 20: permutation 21: perturbation 22: portraiture 23: praseodymium 24: stupefaction 25: sulfonamide
F#
<lang fsharp> // Words which containing all the vowels once . Nigel Galloway: February 17th., 2021 let fN g=if String.length g < 11 then false else let n=Map.ofSeq (Seq.countBy id g) in let fN g=n.ContainsKey g && n.[g]=1 in fN 'a' && fN 'i' && fN 'o' && fN 'u' && fN 'e' 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") </lang>
- Output:
ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide
Factor
<lang factor>USING: grouping io.encodings.ascii io.files math prettyprint sequences sets.extras ;
"unixdict.txt" ascii file-lines [ length 10 > ] filter [ non-repeating "aeiou" superset? ] filter 5 group simple-table.</lang>
- Output:
ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide
Forth
<lang forth>: contains-all-vowels-once ( addr u -- ? )
0 { vowels } 0 do dup c@ case 'a' of 1 endof 'e' of 2 endof 'i' of 4 endof 'o' of 8 endof 'u' of 16 endof 0 swap endcase dup 0<> if vowels or dup vowels = if unloop 2drop false exit then to vowels else drop then 1+ loop drop vowels 31 = ;
256 constant max-line create line-buffer max-line 2 + allot
- main
0 0 { count fd-in } s" unixdict.txt" r/o open-file throw to fd-in begin line-buffer max-line fd-in read-line throw while dup 10 > if line-buffer swap 2dup contains-all-vowels-once if count 1+ to count count 2 .r ." . " type cr else 2drop then else drop then repeat drop fd-in close-file throw ;
main bye</lang>
- Output:
1. ambidextrous 2. bimolecular 3. cauliflower 4. communicable 5. communicate 6. consanguine 7. consultative 8. countervail 9. exclusionary 10. grandiloquent 11. importunate 12. incommutable 13. incomputable 14. insupportable 15. loudspeaking 16. malnourished 17. mensuration 18. oneupmanship 19. pandemonium 20. permutation 21. perturbation 22. portraiture 23. praseodymium 24. stupefaction 25. sulfonamide
Go
<lang go>package main
import (
"bytes" "fmt" "io/ioutil" "log" "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 for _, bword := range bwords { s := string(bword) if utf8.RuneCountInString(s) > 10 { words = append(words, s) } } count := 0 fmt.Println("Words which contain all 5 vowels once in", wordList, "\b:\n") for _, word := range words { ca, ce, ci, co, cu := 0, 0, 0, 0, 0 for _, r := range word { switch r { case 'a': ca++ case 'e': ce++ case 'i': ci++ case 'o': co++ case 'u': cu++ } } if ca == 1 && ce == 1 && ci == 1 && co == 1 && cu == 1 { count++ fmt.Printf("%2d: %s\n", count, word) } }
}</lang>
- Output:
Words which contain all 5 vowels once in unixdict.txt: 1: ambidextrous 2: bimolecular 3: cauliflower 4: communicable 5: communicate 6: consanguine 7: consultative 8: countervail 9: exclusionary 10: grandiloquent 11: importunate 12: incommutable 13: incomputable 14: insupportable 15: loudspeaking 16: malnourished 17: mensuration 18: oneupmanship 19: pandemonium 20: permutation 21: perturbation 22: portraiture 23: praseodymium 24: stupefaction 25: sulfonamide
Julia
See Alternade_words for the foreachword function. <lang julia>hassallthevowels(w, d) = all(c -> count(x -> x == c, w) == 1, collect("aeiou")) ? w : "" foreachword("unixdict.txt", hassallthevowels, colwidth=18, minlen=11, numcols=5)
</lang>
- Output:
Word source: unixdict.txt
ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide
Perl
<lang perl>#!/usr/bin/perl
use strict; use warnings;
@ARGV = 'unixdict.txt'; length > 11 and !/([aeiou]).*\1/ and tr/aeiou// == 5 and print while <>;</lang>
- Output:
ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide
Phix
function onev(string word, integer vowel) return length(find_all(vowel,word))=1 end function function allv(string word) return length(word)>10 and sum(apply(true,onev,{{word},"aeiou"}))=5 end function sequence fivev = filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),allv) printf(1,"%d words: %s\n",{length(fivev),join(shorten(fivev,"",3))})
- Output:
25 words: ambidextrous bimolecular cauliflower ... praseodymium stupefaction sulfonamide
Raku
Yet another "Filter a word list" task.
<lang perl6>put +.words, " words found:\n", $_ with 'unixdict.txt'.IO.words\
.grep({ .chars > 10 and all(.comb.Bag<a e i o u>) == 1 })\ .batch(5)».fmt('%-13s').join: "\n";</lang>
- Output:
25 words found: ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide
REXX
These REXX versions don'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 is caseless.
They also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
version 1
<lang rexx>/*REXX pgm finds all words that contain only one vowel each (no duplication of vowels). */ parse arg minL iFID . /*obtain optional arguments from the CL*/ if minL== | minL=="," then minL= 11 /*Not specified? Then use the default.*/ if iFID== | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ @.= /*default value of any dictionary word.*/
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: original case and the semaphore*/ end /*#*/ /* [↑] semaphore name is uppercased. */
- = # - 1 /*adjust word count because of DO loop.*/
finds= 0 /*count of the alternade words found. */ say copies('─', 30) # "words in the dictionary file: " iFID vowels= 'aeiou'; upper vowels /*create a list of vowels; uppercase it*/ say; Lv= length(vowels) /*obtain the number of vowels (faster).*/
do j=1 for #; L= length($.j) /*process all the words that were found*/ if L<minL then iterate /*Is word too short? Then ignore it. */ y= $.j; upper y /*uppercase the dictionary word. */ if verify(vowels, y)>0 then iterate /*The word have a least each vowel ? */ /* ◄──── optional test (for speed).*/ do k=1 for Lv /*process each of the vowels specified.*/ v= substr(vowels, k, 1) /*extract a vowel from the vowel list. */ _= pos(v, y) /*find the position of the first vowel.*/ if pos(v, y, _+1)\==0 then iterate j /*Is there another (of the same) ··· */ end /*k*/ /* ··· vowel? Yes, then skip it. */ finds= finds + 1 /*bump the count of alternades found.*/ say right( left($.j, 25), 40) /*indent the word for a better display.*/ end /*j*/ /*stick a fork in it, we're all done. */
say copies('─',30) finds ' words found with only one each of every vowel,' ,
" and with a minimum length of " minL</lang>
- output when using the internal default input:
────────────────────────────── 25104 words in the dictionary file: unixdict.txt ambidextrous bimolecular cauliflower communicable communicate consanguine consultative countervail exclusionary grandiloquent importunate incommutable incomputable insupportable loudspeaking malnourished mensuration oneupmanship pandemonium permutation perturbation portraiture praseodymium stupefaction sulfonamide ────────────────────────────── 25 words found with only one each of every vowel, and with a minimum length of 11
version 2
This REXX version uses the countstr BIF which returns the count of (a particular) character in a string. <lang rexx>/*REXX pgm finds all words that contain only one vowel each (no duplication of vowels). */ parse arg minL iFID . /*obtain optional arguments from the CL*/ if minL== | minL=="," then minL= 11 /*Not specified? Then use the default.*/ if iFID== | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ @.= /*default value of any dictionary word.*/
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: original case and the semaphore*/ end /*#*/ /* [↑] semaphore name is uppercased. */
- = # - 1 /*adjust word count because of DO loop.*/
finds= 0 /*count of the alternade words found. */ say copies('─', 30) # "words in the dictionary file: " iFID vowels= 'aeiou'; upper vowels /*create a list of vowels; uppercase it*/ say; Lv= length(vowels)
do j=1 for #; L= length($.j) /*process all the words that were found*/ if L<minL then iterate /*Is word too short? Then ignore it. */ y= $.j; upper y /*uppercase the dictionary word. */ if verify(vowels, y)>0 then iterate /*The word have a least each vowel ? */ /* ◄──── optional test (for speed).*/ do k=1 for Lv /*process each of the vowels specified.*/ _= substr(vowels, k, 1) /*obtain a particular vowel for search.*/ if countstr(_, y)\==1 then iterate j /*Does this word have only one of ··· */ end /*k*/ /* ··· this vowel? No, then skip it. */ finds= finds + 1 /*bump the count of alternades found.*/ say right( left($.j, 25), 40) /*indent the word for a better display.*/ end /*j*/ /*stick a fork in it, we're all done. */
say copies('─',30) finds ' words found with only one each of every vowel,' ,
" and with a minimum length of " minL</lang>
- output is identical to the 1st REXX version.
Ring
<lang ring> load "stdlib.ring"
cStr = read("unixdict.txt") wordList = str2list(cStr) num = 0 same = [] vowels = "aeiou"
see "working..." + nl
ln = len(wordList) for n = ln to 1 step -1
if len(wordList[n]) < 11 del(wordList,n) ok
next
for n = 1 to len(wordList)
flag = 1 str = wordList[n] stra = count(str,"a") stre = count(str,"e") stri = count(str,"i") stro = count(str,"o") stru = count(str,"u") strtmp = [stra,stre,stri,stro,stru] ln = len(strtmp) for m = 1 to ln if strtmp[m] != 1 flag = 0 exit ok next if flag = 1 num = num + 1 see "" + num + ". " + wordList[n] + nl ok
next
see "done..." + nl
func count(cString,dString)
sum = 0 while substr(cString,dString) > 0 sum = sum + 1 cString = substr(cString,substr(cString,dString)+len(string(sum))) end return sum
</lang>
- Output:
working... 1. ambidextrous 2. bimolecular 3. cauliflower 4. communicable 5. communicate 6. consanguine 7. consultative 8. countervail 9. exclusionary 10. grandiloquent 11. importunate 12. incommutable 13. incomputable 14. insupportable 15. loudspeaking 16. malnourished 17. mensuration 18. oneupmanship 19. pandemonium 20. permutation 21. perturbation 22. portraiture 23. praseodymium 24. stupefaction 25. sulfonamide done...
Swift
<lang swift>import Foundation
func containsAllVowelsOnce(_ word: String) -> Bool {
var vowels = 0 for ch in word { var bit = 0 switch (ch) { case "a", "A": bit = 1 case "e", "E": bit = 2 case "i", "I": bit = 4 case "o", "O": bit = 8 case "u", "U": bit = 16 default: break } if bit == 0 { continue } if ((vowels & bit) != 0) { return false } vowels |= bit } return vowels == 31
}
do {
try String(contentsOfFile: "unixdict.txt", encoding: String.Encoding.ascii) .components(separatedBy: "\n") .filter{$0.count > 10 && containsAllVowelsOnce($0)} .enumerated() .forEach{print(String(format: "%2d. %@", $0.0 + 1, $0.1))}
} catch {
print(error.localizedDescription)
}</lang>
- Output:
1. ambidextrous 2. bimolecular 3. cauliflower 4. communicable 5. communicate 6. consanguine 7. consultative 8. countervail 9. exclusionary 10. grandiloquent 11. importunate 12. incommutable 13. incomputable 14. insupportable 15. loudspeaking 16. malnourished 17. mensuration 18. oneupmanship 19. pandemonium 20. permutation 21. perturbation 22. portraiture 23. praseodymium 24. stupefaction 25. sulfonamide
Wren
<lang ecmascript>import "io" for File import "/fmt" for Fmt
var wordList = "unixdict.txt" // local copy var count = 0 File.read(wordList).trimEnd().split("\n").
where { |w| return w.count > 10 && "aeiou".all { |v| return w.count { |c| c == v } == 1 } }. each { |w| count = count + 1 Fmt.print("$2d: $s", count, w) }</lang>
- Output:
1: ambidextrous 2: bimolecular 3: cauliflower 4: communicable 5: communicate 6: consanguine 7: consultative 8: countervail 9: exclusionary 10: grandiloquent 11: importunate 12: incommutable 13: incomputable 14: insupportable 15: loudspeaking 16: malnourished 17: mensuration 18: oneupmanship 19: pandemonium 20: permutation 21: perturbation 22: portraiture 23: praseodymium 24: stupefaction 25: sulfonamide