Last active
October 2, 2019 07:41
-
-
Save calware/75cf54c493765b5aba90089cc3f930eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-- 1 | |
1 1 | |
1 2 1 | |
1 3 3 1 | |
1 4 6 4 1 --} | |
-- printRow :: (Integral a, Show a) => a -> [a] -> IO () | |
printRow :: Int -> [Int] -> IO () | |
printRow pad nums = let printPad c = putStr [' ' | _ <- [1..c]] | |
in do | |
printPad pad | |
putStrLn [x | ent <- nums, x <- ((show ent) ++ " " )] | |
-- genRow :: (Integral a) => [a] -> [a] | |
genRow :: [Int] -> [Int] | |
genRow prev = [1] ++ newRow ++ [1] | |
where newRow = zipWith (+) prev (tail prev) | |
-- couldn't define a type signature here like i wanted to | |
-- build :: (Integral a, Show a) => [a] -> a -> IO () | |
build :: [Int] -> Int -> IO () | |
build row size | |
| padding < 0 = putChar '\n' | |
| otherwise = do | |
printRow padding row | |
build (genRow row) size | |
where padding = size - (length row) | |
main = do | |
putChar '\n' | |
build [1] 5 | |
putStrLn ":^)\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment