Prepares e_7 for challenge. Finishes e_6

This commit is contained in:
Julien Lengrand-Lambert
2012-01-12 23:40:34 +01:00
parent 8d1a14a937
commit 39da55e2a1
2 changed files with 44 additions and 3 deletions

20
e_6.py
View File

@@ -9,12 +9,26 @@
natural numbers and the square of the sum. natural numbers and the square of the sum.
#--- #---
""" """
def sum_squares(): def diff_sum_squares(value):
""" """
Returns the difference between the sum of the squares of the first one Returns the difference between the sum of the squares of the first one
hundred natural numbers and the square of the sum. hundred natural numbers and the square of the sum.
""" """
return 1 return squares_sum(value) - sum_squares(value)
def sum_squares(value):
"""
Returns the sum of the square of elements from 1 to value
"""
vals = range(1, value + 1)
return sum([pow(val, 2) for val in vals])
def squares_sum(value):
"""
Returns the square of the sum of elements from 1 to value
"""
return pow(sum(range(1, value + 1)), 2)
if __name__ == '__main__': if __name__ == '__main__':
print "Answer : %d " % (sum_squares()) val = 100
print "Answer : %d " % (diff_sum_squares(val))

27
e_7.py Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python
"""
#---
Julien Lengrand-Lambert
Created on : Wed Jan 11 14:42:54 CET 2012
DESCRIPTION : Solves problem 7 of Project Euler
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
that the 6th prime is 13.
What is the 10 001st prime number?
#---
"""
def prime_list(value):
"""
Returns the vlst prime number
"""
return 1
if __name__ == '__main__':
val = 10001
print "Answer : %d " % (prime_list(val))