Left factorials: Difference between revisions
Content added Content deleted
(Added Quackery.) |
|||
Line 2,679: | Line 2,679: | ||
{{Trans|Haskell}} |
{{Trans|Haskell}} |
||
<lang python> |
<lang python>'''Left factorials''' |
||
from itertools import (accumulate, chain, count, islice) |
from itertools import (accumulate, chain, count, islice) |
||
Line 2,687: | Line 2,687: | ||
# leftFact :: [Integer] |
# leftFact :: [Integer] |
||
def leftFact(): |
def leftFact(): |
||
'''Left factorial series defined in terms |
'''Left factorial series defined in terms |
||
of the factorial series. |
|||
⚫ | |||
''' |
|||
⚫ | |||
⚫ | |||
) |
) |
||
Line 2,695: | Line 2,697: | ||
# fact :: [Integer] |
# fact :: [Integer] |
||
def fact(): |
def fact(): |
||
''' |
'''The factorial series. |
||
⚫ | |||
⚫ | |||
return accumulate( |
|||
⚫ | |||
) |
) |
||
# |
# ------------------------- TEST ------------------------- |
||
# main :: IO () |
# main :: IO () |
||
def main(): |
def main(): |
||
Line 2,725: | Line 2,728: | ||
# |
# ----------------------- GENERIC ------------------------ |
||
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c |
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c |
||
Line 2,731: | Line 2,734: | ||
'''Function composition.''' |
'''Function composition.''' |
||
return lambda f: lambda x: g(f(x)) |
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 ( |
|||
⚫ | |||
⚫ | |||
# scanl :: (b -> a -> b) -> b -> [a] -> [b] |
# scanl :: (b -> a -> b) -> b -> [a] -> [b] |
||
def scanl(f): |
def scanl(f): |
||
'''scanl is like reduce, but |
'''scanl is like reduce, but defines a succession of |
||
intermediate values, building from the left. |
intermediate values, building from the left. |
||
''' |
|||
return lambda a: lambda xs: ( |
|||
def go(a): |
|||
⚫ | |||
) |
def g(xs): |
||
return accumulate(chain([a], xs), f) |
|||
return g |
|||
⚫ | |||