Jump to content

Pascal's triangle: Difference between revisions

m
→‎Functional Python: Pruned out three unused primitives
m (→‎Functional Python: Pruned out three unused primitives)
Line 4,116:
 
<lang python>from itertools import (accumulate, chain, islice, starmap)
from operator import (add)
 
 
# pascal :: [Int] -> [Int]
def pascal(xs):
return zipWith(plusadd)([0] + xs)(xs + [0])
 
 
Line 4,176 ⟶ 4,177:
return (q * c) + s + ((q + qr[1]) * c)
return lambda c: lambda s: go(c, s)
 
 
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
def compose(g):
return lambda f: lambda x: g(f(x))
 
 
# const :: a -> b -> a
def const(k, _):
return k
 
 
Line 4,201 ⟶ 4,192:
v = f(v)
return lambda x: go(x)
 
 
# plus :: Num -> Num -> Num
def plus(a, b):
return a + b
 
 
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.