From c3e4e6391fa4606538f9012d1c2b52eb23436ca0 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Thu, 12 Jan 2012 16:08:31 +0100 Subject: [PATCH] Solves Problem 5. Prepares Problem 6 --- e_5.py | 18 +++++++++++++++++- e_6.py | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 e_6.py diff --git a/e_5.py b/e_5.py index d0e2ee5..dfa9cab 100755 --- a/e_5.py +++ b/e_5.py @@ -15,8 +15,24 @@ def divisible_by_all(): """ 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__': print "Answer : %d " % (divisible_by_all()) diff --git a/e_6.py b/e_6.py new file mode 100755 index 0000000..3eb13a6 --- /dev/null +++ b/e_6.py @@ -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())