Find words which contains all the vowels: Difference between revisions
Find words which contains all the vowels (view source)
Revision as of 21:13, 10 August 2023
, 10 months ago→{{header|Haskell}}: filter rather than partition (simpler here)
(→{{header|Haskell}}: Added a variant, expressed in terms of Data.Set, which includes the restriction to 10 chars) |
m (→{{header|Haskell}}: filter rather than partition (simpler here)) |
||
Line 1,269:
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.
import Data.
---- WORDS OVER 10 CHARS WHICH CONTAIN EACH VOWEL ONCE ---
Line 1,280 ⟶ 1,278:
eachVowelOnce :: String -> Bool
eachVowelOnce w =
(uncurry (&&) . both (== 5)) $
((,) . length <*> (size . fromList)) $▼
▲ (size . fromList)
▲ (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,
both f ~(x, y) =
{{Out}}
<pre>ambidextrous
|