mirror of
https://github.com/jlengrand/project_euler.git
synced 2026-03-10 08:41:20 +00:00
Solves Problem 5.
Prepares Problem 6
This commit is contained in:
18
e_5.py
18
e_5.py
@@ -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
20
e_6.py
Executable 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())
|
||||||
Reference in New Issue
Block a user