Faulhaber's triangle: Difference between revisions
m
→{{header|Python}}: Pruned one import, updated primitives, tidied.
m (→{{header|Python}}: Pruned one import, updated primitives, tidied.) |
|||
Line 2,267:
<lang python>'''Faulhaber's triangle'''
from itertools import
from fractions import
Line 2,275:
'''List of rows of Faulhaber fractions.'''
def go(rs, n):
xs =
))▼
return [Fraction(1 - sum(xs), 1)] + xs
return list(accumulate(
[[]] + list(islice(count(0), 1 + m)),
Line 2,291:
positive integers.
'''
def go(x, y):
return sum(
▲ lambda x, y: y * (n ** x),
▲ zip(count(1), faulhaberTriangle(p)[-1])
))▼
)
#
def main():
'''Tests'''
Line 2,319:
#
# fTable :: String -> (a -> String) ->
#
def fTable(s):
'''Heading -> x
fx display function
'''
def
))▼
def arrowed(x, y):
return y.rjust(w, ' ') + ' -> ' + (
fxShow(f(x))
)▼
)
return s + '\n' + '\n'.join(
map(arrowed, xs, ys)
return goxs
return gof
return gox
#
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
Line 2,351 ⟶ 2,359:
def concat(xs):
'''The concatenation of all the elements
in a list or iterable.
def f(ys):
zs = list(chain(*ys))
Line 2,368 ⟶ 2,377:
f lifted to a function over a list.
'''
return list(map(f, xs))
return go
Line 2,386 ⟶ 2,398:
representation of the ratio r.
'''
def go(n
('
' ' * (1 + n)
)
return
|