September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,20 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
'''Long multiplication'''
|
||||
|
||||
def digits(x):
|
||||
return [int(c) for c in str(x)]
|
||||
from functools import reduce
|
||||
|
||||
def mult_table(xs, ys):
|
||||
return [[x * y for x in xs] for y in ys]
|
||||
|
||||
def polymul(xs, ys):
|
||||
return map(lambda *vs: sum(filter(None, vs)),
|
||||
*[[0] * i + zs for i, zs in enumerate(mult_table(xs, ys))])
|
||||
|
||||
def longmult(x, y):
|
||||
result = 0
|
||||
for v in polymul(digits(x), digits(y)):
|
||||
result = result * 10 + v
|
||||
return result
|
||||
'''Long multiplication.'''
|
||||
return reduce(
|
||||
digitSum,
|
||||
polymul(digits(x), digits(y)), 0
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print longmult(2**64, 2**64)
|
||||
|
||||
def digitSum(a, x):
|
||||
'''Left to right decimal digit summing.'''
|
||||
return a * 10 + x
|
||||
|
||||
|
||||
def polymul(xs, ys):
|
||||
'''List of specific products.'''
|
||||
return map(
|
||||
lambda *vs: sum(filter(None, vs)),
|
||||
*[
|
||||
[0] * i + zs for i, zs in
|
||||
enumerate(mult_table(xs, ys))
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def mult_table(xs, ys):
|
||||
'''Rows of all products.'''
|
||||
return [[x * y for x in xs] for y in ys]
|
||||
|
||||
|
||||
def digits(x):
|
||||
'''Digits of x as a list of integers.'''
|
||||
return [int(c) for c in str(x)]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(
|
||||
longmult(2 ** 64, 2 ** 64)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue