Find words containing every vowel
GolfScript, 19 characters
n%{'aeiouy'&,6=},n*
Usage:
golfscript vowels.gs < wordlist.txt
Output:
abstemiously
authoritatively
behaviourally
[...]
uninformatively
unintentionally
unquestionably
unrecognisably
If you also want to output the count at the end you can use
n%{'aeiouy'&,6=},.n*n@,
which is four characters longer.
Python - 46 characters
filter(lambda x:set(x)>=set("AEIOUY"),open(f))
Readable version: It's already pretty readable :-)
Ruby 38
Edit 34: Best so far (from @O-I):
a.split.select{|w|'aeiouy'.count(w)>5}
Edit 1: I just noticed the question asked for 'y' to be included among the vowels, so I've edited my question accordingly. As @Nik pointed out in a comment to his answer, "aeiouy".chars
is one character less than %w[a e i o u y]
, but I'll leave the latter, for diversity, even though I'm risking nightmares over the opportunity foregone.
Edit 2: Thanks to @O-I for suggesting the improvement:
s.split.select{|w|'aeiouy'.delete(w)==''}
which saves 11 characters from what I had before.
Edit 3 and 3a: @O-I has knock off a few more:
s.split.select{|w|'aeiouy'.tr(w,'')==''}
then
s.split.reject{|w|'aeiouy'.tr(w,'')[1]}
and again (3b):
a.split.select{|w|'aeiouy'.count(w)>5}
I am a mere scribe!
Here are two more uncompettive solutions:
s.split.group_by{|w|'aeiouy'.delete(w)}[''] (43)
s.gsub(/(.+)\n/){|w|'aeiouy'.delete(w)==''?w:''} (48)
Initially I had:
s.split.select{|w|(w.chars&%w[a e i o u y]).size==6}
s
is a string containing the words, separated by newlines. An array of words from s
that contains all five vowels is returned. For readers unfamiliar with Ruby, %w[a e i o u y] #=> ["a", "e", "i", "o", "u", "y"]
and &
is array intersection.
Suppose
s = "abbreviations\nabduction\n"
s.split #=> ["abbreviations", "abduction"]
In the block {...}
, initially
w #=> "abbreviations"
w.chars #=> ["a", "b", "b", "r", "e", "v", "i", "a", "t", "i", "o", "n", "s"]
w.chars & %w[a e i o u y] #=> ["a", "e", "i", "o"]
(w.chars & %w[a e i o u y]).size == 6 #=> (4 == 6) => false,
so "abbreviations" is not selected.
If the string s
may contain duplicates, s.split.select...
can be replaced by s.split.uniq.select...
to remove duplicates.
Just noticed I could save 1 char by replacing size==6
with size>5
.