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.

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

Pretty much the same thing I did, minus self-recursive definition shenanigans:

pascal = iterate ((++ [1]) . (1:) . (zipWith (+) =<< tail)) [1]

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=[1]:map ((1:).(++[1]).(zipWith (+)=<<tail)) s

I could come up with a shorter one, here is your s function without spaces:

s

s=[1]:map((1:).(++[1]).(zipWith(+)=<<tail))s

which is longer by 5 characters than:

p=[1]:[1:zipWith(+)r t++[1]|r@(_:t)<-p]

Spectacular "pointless" style. I couldn't help but chuckled on 'flip'.

## Pascal's Triangle

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:

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

Pretty much the same thing I did, minus self-recursive definition shenanigans:

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:

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'.