I wrote up a small script to calculate the answer to Project Euler Problem 5:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
I'm wondering if this algorithm can be improved or made more efficient:
def divisible_by(num, den_set): if not den_set: return True elif not num % den_set.pop(): return divisible_by(num, den_set) else: return False def smallest(den_count): i = 1 den_set = list(range(1, den_count)) while not divisible_by(i, den_set): den_set = list(range(1, den_count)) i += 1 return i print smallest(20)