Left factorials: Difference between revisions
m
→{{header|Python}}
(Added Quackery.) |
|||
Line 2,679:
{{Trans|Haskell}}
<lang python>
from itertools import (accumulate, chain, count, islice)
Line 2,687:
# leftFact :: [Integer]
def leftFact():
'''Left factorial series defined in terms
of the factorial series.
return scanl(add)(0)(▼
)
Line 2,695 ⟶ 2,697:
# fact :: [Integer]
def fact():
'''
return scanl(mul)(1)(▼
return
)
#
# main :: IO ()
def main():
Line 2,725 ⟶ 2,728:
#
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
Line 2,731 ⟶ 2,734:
'''Function composition.'''
return lambda f: lambda x: g(f(x))
▲ map(chr, count(ord(x)))
▲ )
# scanl :: (b -> a -> b) -> b -> [a] -> [b]
def scanl(f):
'''scanl is like reduce, but
intermediate values, building from the left.
'''
def go(a):
▲ accumulate(chain([a], xs), f)
def g(xs):
return accumulate(chain([a], xs), f)
return g
|