Find words with alternating vowels and consonants: Difference between revisions
Content deleted Content added
Line 569: | Line 569: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>import Data.List.Split (chunksOf) |
|||
⚫ | |||
⚫ | |||
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 |
&& 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 = |
main = |
||
readFile "unixdict.txt" >>= \s -> |
|||
mapM_ putStrLn $ |
mapM_ putStrLn $ |
||
((:) =<< (<> " matching words:\n") . show . length) $ |
((:) =<< (<> " matching words:\n") . show . length) $ |
||
filter isLongAlternator (lines s) |
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: |