1.Please list all the squares, below 6000, that are the sum of three distinct factorials.
2.Same task, without the "distinct" condition.
Since 8! is greater than 6,000, we only need to check sums that involve factorials of digits up to 7. The following checks for part 1:
squares = []
for a in range(6):
for b in range(a+1,7):
for c in range(b+1,8):
f = factorial(a) + factorial(b) + factorial(c)
if sqrt(f) == floor(sqrt(f)) and f not in squares:
squares.append(f)
print a, b, c, f
and produces:
0 1 2 4
0 2 3 9
0 5 6 841
4 5 7 5184
For part 2, a simple tweak to the code checks without the distinct condition and produces two more results:
0 0 2 4
0 2 3 9
0 4 4 49
0 5 6 841
3 3 4 36
4 5 7 5184
|
Posted by tomarken
on 2014-03-15 11:02:55 |