tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,9 @@
def pascal(n):
"""Prints out n rows of Pascal's triangle.
It returns False for failure and True for success."""
row = [1]
k = [0]
for x in range(max(n,0)):
print row
row=[l+r for l,r in zip(row+k,k+row)]
return n>=1

View file

@ -0,0 +1,17 @@
def scan(op, seq, it):
a = []
result = it
a.append(it)
for x in seq:
result = op(result, x)
a.append(result)
return a
def pascal(n):
def nextrow(row, x):
return [l+r for l,r in zip(row+[0,],[0,]+row)]
return scan(nextrow, range(n-1), [1,])
for row in pascal(4):
print(row)