Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sample Input:
- -- 6
- --
- -- Sample Output:
- -- #
- -- ##
- -- ###
- -- ####
- -- #####
- -- ######
- --
- -- It should be possible to make the below solution shorter and clearer
- -- by using higher order functions and/or function composition...
- module Main where
- main :: IO ()
- main = readLn >>= \n -> putStr $ staircase n n ""
- staircase :: Int -> Int -> [Char] -> [Char]
- staircase 0 current string = string
- staircase total 0 string = string
- staircase total current string = staircase total (current-1) $ stair total current string
- stair :: Int -> Int -> [Char] -> [Char]
- --stair total 0 string = string
- stair total current string = string++((stairPart (current-1) ' '))++(stairPart (total - (current-1)) '#')++"\n"
- stairPart :: Int -> a -> [a]
- stairPart n character = replicate n character
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement