Find words which contains all the vowels: Difference between revisions
Content deleted Content added
→{{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: | 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: |
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. |
<syntaxhighlight lang="haskell">import Data.List (partition) |
||
import Data. |
import Data.Set (Set, fromList, member, size) |
||
import Data.Bifunctor (bimap) |
|||
import Control.Monad (join) |
|||
---- WORDS OVER 10 CHARS WHICH CONTAIN EACH VOWEL ONCE --- |
---- WORDS OVER 10 CHARS WHICH CONTAIN EACH VOWEL ONCE --- |
||
Line 1,280: | Line 1,278: | ||
eachVowelOnce :: String -> Bool |
eachVowelOnce :: String -> Bool |
||
eachVowelOnce w = |
eachVowelOnce w = |
||
uncurry (&&) $ |
(uncurry (&&) . both (== 5)) $ |
||
⚫ | |||
both (5 ==) |
|||
⚫ | |||
(bimap |
|||
⚫ | |||
((-) (length w) . length) |
|||
⚫ | |||
⚫ | |||
vowels :: Set Char |
vowels :: Set Char |
||
vowels = fromList "aeiou" |
vowels = fromList "aeiou" |
||
--------------------------- TEST ------------------------- |
--------------------------- TEST ------------------------- |
||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
readFile "unixdict.txt" |
readFile "unixdict.txt" |
||
>>= (mapM_ putStrLn . filter p . lines) |
>>= (mapM_ putStrLn . filter p . lines) |
||
⚫ | |||
------------------------- GENERIC ------------------------ |
------------------------- GENERIC ------------------------ |
||
both :: (a -> b) -> (a, |
both :: (a -> b) -> (a, a) -> (b, b) |
||
both = |
both f ~(x, y) = (f x, f y)</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>ambidextrous |
<pre>ambidextrous |