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>import Data.List (transpose)
import Data.List.Split (chunksOf)


------ WORDS WITHOUT SUCCESSIVE VOWELS OR CONSONANTS -----
------ WORDS WITHOUT SUCCESSIVE VOWELS OR CONSONANTS -----
Line 587: Line 588:
mapM_ putStrLn $
mapM_ putStrLn $
((:) =<< (<> " matching words:\n") . show . length) $
((:) =<< (<> " matching words:\n") . show . length) $
filter isLongAlternator (lines s)
filter isLongAlternator (lines s)</lang>

------------------------ 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: