DEV Community

Discussion on: Daily Challenge #201 - Complete the Pattern

Collapse
 
avalander profile image
Avalander

Haskell

pattern :: Int -> String
pattern n
  | n > 0     = unlines [repeatNum x | x <- [1..n]]
  | otherwise = ""
  where
    repeatNum x = foldl (++) "" $ take x $ repeat $ show x

Output:

pattern 4
{-
1
22
333
4444
-}

pattern 8
{-
1
22
333
4444
55555
666666
7777777
88888888
-}

pattern 0.5
-- Compiler error, ha ha.