–For details of Pascal’s_triangle go through : http://en.wikipedia.org/wiki/Pascal’s_triangle

— Haskell is good at lazy evaluation ,Using that here is infinite Pascal’s_triangle

pascalTriangle = lazyPascaltriangle [1]

lazyPascaltriangle xs = xs : lazyPascaltriangle((head xs):pairSum xs)

where pairSum [] = []

pairSum [x] = [x]

pairSum (x:y:xs) = (x+y):pairSum (y:xs)

–sample run

take 6 pascalTriangle

[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1]]

Advertisements