Pascal's triangle: Difference between revisions

Content added Content deleted
m (→‎Functional Pascal: Updated preamble)
Line 4,150: Line 4,150:
def main():
def main():
'''Test of two different approaches:
'''Test of two different approaches:
- taking from a non-finite stream of rows
- taking from a non-finite stream of rows,
- constructing a finite list of rows'''
- or constructing a finite list of rows.'''
print(unlines(map(
print(unlines(map(
showPascal,
showPascal,
[
[
take(7)(pascalTriangle()), # Non finite,
take(7)(
pascalTriangle() # Non finite,
),
finitePascalRows(7) # finite.
finitePascalRows(7) # finite.
]
]
Line 4,181: Line 4,183:
def center(n):
def center(n):
'''String s padded with c to approximate centre,
'''String s padded with c to approximate centre,
fitting in but not truncated to width n.
fitting in but not truncated to width n.'''
'''
def go(c, s):
def go(c, s):
qr = divmod(n - len(s), 2)
qr = divmod(n - len(s), 2)