You are viewing a single comment's thread. Return to all 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.
 : map nextRow pascalTriangle
nextRow = ( ++). (++ ). pairSum
pairSum x = zipWith (+) x (tail x)
map listToString pascalTriangle
listToString = unwords. map show
main = getLine >>= putStrLn. unlines. flip take showPascalTriangle. read
Pretty much the same thing I did, minus self-recursive definition shenanigans:
pascal = iterate ((++ ) . (1:) . (zipWith (+) =<< tail)) 
Bases on your solutions and adding a bit of my own, I think this might be the shorstest way to solve this, using just the Prelude:
main=interact$unlines.map (unwords.(map show)).flip take s.read
s=:map ((1:).(++).(zipWith (+)=<<tail)) s
I could come up with a shorter one, here is your s function without spaces:
which is longer by 5 characters than:
Spectacular "pointless" style.
I couldn't help but chuckled on 'flip'.