nayuki / Project-Euler-solutions

Runnable code for solving Project Euler problems in Java, Python, Mathematica, Haskell.
https://www.nayuki.io/page/project-euler-solutions
1.89k stars 675 forks source link

suggestion #19

Closed gregbo closed 5 years ago

gregbo commented 5 years ago

Incidentally, the solution to Problem 6 can be further simplified as the product of linear terms and a constant:

n(n-1)(n+1)(3n+2)/12

qinggeouye commented 5 years ago

p008.py

def digit_product(s): return reduce(lambda x, y: x*y, map(int, [i for i in s]))

nayuki commented 5 years ago

@gregbo But how many lines of algebra formulas do you need to write to justify that simplification?

I make a balance between computation time and human understanding. I believe my solution is the most appropriate for the small problem size.