Find words with alternating vowels and consonants: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
Hout (talk | contribs)
Line 569: Line 569:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.List.Split (chunksOf)
<lang haskell>------ WORDS WITHOUT SUCCESSIVE VOWELS OR CONSONANTS -----

------ WORDS WITHOUT SUCCESSIVE VOWELS OR CONSONANTS -----


isLongAlternator :: String -> Bool
isLongAlternator :: String -> Bool
isLongAlternator s =
isLongAlternator s =
9 < length s
9 < length s
&& all (\(a, b) -> isVowel a /= isVowel b) (zip s (tail s))
&& all (\(a, b) -> isVowel a /= isVowel b) (zip s $ tail s)


isVowel :: Char -> Bool
isVowel :: Char -> Bool
Line 581: Line 583:
--------------------------- TEST -------------------------
--------------------------- TEST -------------------------
main :: IO ()
main :: IO ()
main = do
main =
s <- readFile "unixdict.txt"
readFile "unixdict.txt" >>= \s ->
mapM_ putStrLn $
mapM_ putStrLn $
((:) =<< (<> " matching words:\n") . show . length) $
((:) =<< (<> " matching words:\n") . show . length) $
filter isLongAlternator (lines s)</lang>
filter isLongAlternator (lines s)

------------------------ FORMATTING ----------------------

paddedCols :: Show a => [[a]] -> [[String]]
paddedCols cols =
let cells = fmap show <$> cols
w = maximum $ length <$> concat cells
in map (justifyRight w ' ') <$> cells

justifyRight n c = (drop . length) <*> (replicate n c <>)</lang>
{{Out}}
{{Out}}
<pre>67 matching words:
<pre>67 matching words: