Last active
December 17, 2015 12:29
-
-
Save maxp/5610534 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| # from functools import reduce | |
| # from itertools import product | |
| from time import time | |
| t0 = time() | |
| digs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
| sums = {i:0 for i in range(28)} | |
| # for s in product(digs, digs, digs): | |
| # sums[sum(s)] += 1 | |
| # result = reduce(lambda a, x: a+x*x, sums.values()) - 1 | |
| # short form: | |
| # https://gist.github.com/klen/5610667 | |
| # result = sum(1 for a, b in product(map(sum, product(range(10), repeat=3)), repeat=2) if a == b) - 1 | |
| # | |
| # https://gist.github.com/klen/5610784 | |
| # from itertools import product, groupby | |
| # result = sum([len(tuple(g)) ** 2 for _, g in groupby(sorted(map(sum, product(range(10), repeat=3))))]) - 1 | |
| for d1 in digs: | |
| for d2 in digs: | |
| for d3 in digs: | |
| sums[d1+d2+d3] += 1 | |
| result = -1 | |
| for s in sums.values(): | |
| result += s*s | |
| t1 = time() | |
| print( result, t1-t0 ) | |
| #. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment