Pascal's triangle: Difference between revisions
Content added Content deleted
m (→Functional Python: Pruned out three unused primitives) |
|||
Line 4,116: | Line 4,116: | ||
<lang python>from itertools import (accumulate, chain, islice, starmap) |
<lang python>from itertools import (accumulate, chain, islice, starmap) |
||
from operator import (add) |
|||
# pascal :: [Int] -> [Int] |
# pascal :: [Int] -> [Int] |
||
def pascal(xs): |
def pascal(xs): |
||
return zipWith( |
return zipWith(add)([0] + xs)(xs + [0]) |
||
Line 4,176: | Line 4,177: | ||
return (q * c) + s + ((q + qr[1]) * c) |
return (q * c) + s + ((q + qr[1]) * c) |
||
return lambda c: lambda s: go(c, s) |
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: | Line 4,192: | ||
v = f(v) |
v = f(v) |
||
return lambda x: go(x) |
return lambda x: go(x) |
||
# plus :: Num -> Num -> Num |
|||
def plus(a, b): |
|||
return a + b |
|||