This problem over at Project Euler turned out to be a lot simpler than expected. Forty-Three other problems have been solved more times than this one; yet, it was dead simple. Really, there is nothing interesting in its solution, unlike Problem #97 that I posted about yesterday.

It’s straight combinatorics and factorials. So read the problem page and be amazed at what a gimme this one is :)

Result: [snip]

Time: 0.321524143219

#!/usr/bin/python

import time

def factorial(n):

if n > 1:

return n * factorial(n–1)

else:

return 1

def combinations(r,n):

return factorial(n)/(factorial(r)*factorial(n-r))

total = 0

start = time.time()

for n in range (1,101):

for r in range(1, n+1):

if combinations(r,n) > 1000000:

total += 1

stop = time.time()

print “Result:”, total

print “Time:”, str(stop-start)

import time

def factorial(n):

if n > 1:

return n * factorial(n–1)

else:

return 1

def combinations(r,n):

return factorial(n)/(factorial(r)*factorial(n-r))

total = 0

start = time.time()

for n in range (1,101):

for r in range(1, n+1):

if combinations(r,n) > 1000000:

total += 1

stop = time.time()

print “Result:”, total

print “Time:”, str(stop-start)