• + 2 comments

    I am using a trick where infinte series can be used to contruct the same series, similar to how fibonacci series is generated:

    fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
    

    For pascal triangle, we start using the first row, and then use each row to calculate the next row.

    pascalTriangle = 
        [1] : map nextRow pascalTriangle
      where 
        nextRow = ([1] ++). (++ [1]). pairSum
        pairSum x = zipWith (+) x (tail x)
    
    showPascalTriangle = 
        map listToString pascalTriangle
      where
        listToString = unwords. map show
        
    
    main = getLine >>= putStrLn. unlines. flip take showPascalTriangle. read