Left factorials: Difference between revisions

m
(Added Quackery.)
Line 2,679:
 
{{Trans|Haskell}}
<lang python>"""'''Left factorials"""'''
 
from itertools import (accumulate, chain, count, islice)
Line 2,687:
# leftFact :: [Integer]
def leftFact():
'''Left factorial series defined in terms of the factorial series'''
of the factorial series.
return scanl(add)(0)(
fact()'''
return scanl(add)(0)accumulate(
accumulate(chain([a0], xsfact()), f)add
)
 
Line 2,695 ⟶ 2,697:
# fact :: [Integer]
def fact():
'''FactorialThe factorial series – a non-finite list'''.
)'''
return scanl(mul)(1)(
return enumFromaccumulate(1)
mapchain(chr[1], count(ord(x)1)), mul
)
 
 
# TEST --------------------------- TEST -------------------------
# main :: IO ()
def main():
Line 2,725 ⟶ 2,728:
 
 
# GENERIC ------------------------- GENERIC ------------------------
 
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
Line 2,731 ⟶ 2,734:
'''Function composition.'''
return lambda f: lambda x: g(f(x))
 
 
# enumFrom :: Enum a => a -> [a]
def enumFrom(x):
'''A non-finite stream of enumerable values,
starting from the given value.'''
return count(x) if isinstance(x, int) else (
map(chr, count(ord(x)))
)
 
 
# scanl :: (b -> a -> b) -> b -> [a] -> [b]
def scanl(f):
'''scanl is like reduce, but returnsdefines a succession of
intermediate values, building from the left.'''
'''
return lambda a: lambda xs: (
def go(a):
accumulate(chain([a], xs), f)
def g(xs):
return accumulate(chain([a], xs), f)
return g
return scanl(mul)(1)(go
 
 
9,659

edits