Find words which contains all the vowels: Difference between revisions
Content deleted Content added
→{{header|RPL}}: emulator version capable to read input file |
→{{header|Haskell}}: Added a variant, expressed in terms of Data.Set, which includes the restriction to 10 chars |
||
Line 1,266:
vexatious
</pre>
or, adding the restriction to words of more than 10 characters, and using Data.Set to identify words with a set of 5 unique vowel characters, which have no more than 5 vowel characters in total:
<syntaxhighlight lang="haskell">import Data.Set (Set, fromList, member, size)
import Data.List (partition)
import Data.Bifunctor (bimap)
import Control.Monad (join)
---- WORDS OVER 10 CHARS WHICH CONTAIN EACH VOWEL ONCE ---
p :: String -> Bool
p = ((&&) . (10 <) . length) <*> eachVowelOnce
eachVowelOnce :: String -> Bool
eachVowelOnce w =
uncurry (&&) $
both (5 ==)
(bimap
(size . fromList)
((-) (length w) . length)
(partition (`member` vowels) w)
)
vowels :: Set Char
vowels = fromList "aeiou"
--------------------------- TEST -------------------------
main :: IO ()
main =
readFile "unixdict.txt"
>>= (mapM_ putStrLn . filter p . lines)
------------------------- GENERIC ------------------------
both :: (a -> b) -> (a, a) -> (b, b)
both = join bimap</syntaxhighlight>
{{Out}}
<pre>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</pre>
=={{header|J}}==
|