Solves Problem 5.

Prepares Problem 6
This commit is contained in:
Julien Lengrand-Lambert
2012-01-12 16:08:31 +01:00
parent b38f8e5a03
commit c3e4e6391f
2 changed files with 37 additions and 1 deletions

18
e_5.py
View File

@@ -15,8 +15,24 @@ def divisible_by_all():
""" """
Returns the smallest number divisible by 1 to 20 Returns the smallest number divisible by 1 to 20
""" """
dividers = range(1, 20)[::-1] # in reverse order
max_div = dividers[0] + 1
ptr = 2
inc = 0
return 1 while 1:
val = max_div * ptr
# if divisible by all dividers
for divider in dividers:
if (val % divider != 0):
break
inc += 1
if inc == len(dividers):
return val
else :
inc = 0
ptr += 1
if __name__ == '__main__': if __name__ == '__main__':
print "Answer : %d " % (divisible_by_all()) print "Answer : %d " % (divisible_by_all())

20
e_6.py Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python
"""
#---
Julien Lengrand-Lambert
Created on : Wed Jan 11 14:42:54 CET 2012
DESCRIPTION : Solves problem 6 of Project Euler
Find the difference between the sum of the squares of the first one hundred
natural numbers and the square of the sum.
#---
"""
def sum_squares():
"""
Returns the difference between the sum of the squares of the first one
hundred natural numbers and the square of the sum.
"""
return 1
if __name__ == '__main__':
print "Answer : %d " % (sum_squares())