Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. -- Sample Input:
  2. -- 6
  3. --
  4. -- Sample Output:
  5. -- #
  6. -- ##
  7. -- ###
  8. -- ####
  9. -- #####
  10. -- ######
  11. --
  12. -- It should be possible to make the below solution shorter and clearer
  13. -- by using higher order functions and/or function composition...
  14.  
  15. module Main where
  16.  
  17. main :: IO ()
  18. main = readLn >>= \n -> putStr $ staircase n n ""
  19.  
  20. staircase :: Int -> Int -> [Char] -> [Char]
  21. staircase 0 current string = string
  22. staircase total 0 string = string
  23. staircase total current string = staircase total (current-1) $ stair total current string
  24.  
  25. stair :: Int -> Int -> [Char] -> [Char]
  26. --stair total 0 string = string
  27. stair total current string = string++((stairPart (current-1) ' '))++(stairPart (total - (current-1)) '#')++"\n"
  28.  
  29. stairPart :: Int -> a -> [a]
  30. stairPart n character = replicate n character
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement