mirror of
https://github.com/correl/euler.git
synced 2024-11-23 19:19:53 +00:00
For problems that include defined utility functions, only run
excecutable code if they are called directly. git-svn-id: file:///srv/svn/euler@29 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
eecb37127f
commit
715e24dcf3
4 changed files with 11 additions and 8 deletions
4
004.py
4
004.py
|
@ -7,5 +7,5 @@ def palindrome():
|
||||||
palindromes[i * ii] = [i, ii]
|
palindromes[i * ii] = [i, ii]
|
||||||
p = sorted(palindromes.keys(), reverse=True)[0]
|
p = sorted(palindromes.keys(), reverse=True)[0]
|
||||||
print 'Palindrome: {0}x{1}: {2}'.format(palindromes[p][0], palindromes[p][1], p)
|
print 'Palindrome: {0}x{1}: {2}'.format(palindromes[p][0], palindromes[p][1], p)
|
||||||
|
if __name__ == '__main__':
|
||||||
palindrome()
|
palindrome()
|
||||||
|
|
4
005.py
4
005.py
|
@ -8,5 +8,5 @@ def divisible(n):
|
||||||
break
|
break
|
||||||
if ii == 1:
|
if ii == 1:
|
||||||
return x
|
return x
|
||||||
|
if __name__ == '__main__':
|
||||||
print 'Smallest number: ', divisible(20)
|
print 'Smallest number: ', divisible(20)
|
||||||
|
|
6
006.py
6
006.py
|
@ -1,9 +1,11 @@
|
||||||
def squarediff(n):
|
def squarediff(n):
|
||||||
|
print 'Checking for n =', n
|
||||||
sumofsquares = sum([x**2 for x in range(n + 1)])
|
sumofsquares = sum([x**2 for x in range(n + 1)])
|
||||||
print 'Sum of squares', sumofsquares
|
print 'Sum of squares', sumofsquares
|
||||||
squareofsum = sum(range(n + 1))**2
|
squareofsum = sum(range(n + 1))**2
|
||||||
print 'Square of sum', squareofsum
|
print 'Square of sum', squareofsum
|
||||||
print 'Difference', squareofsum - sumofsquares
|
print 'Difference', squareofsum - sumofsquares
|
||||||
|
|
||||||
squarediff(10)
|
if __name__ == '__main__':
|
||||||
squarediff(100)
|
squarediff(10)
|
||||||
|
squarediff(100)
|
||||||
|
|
5
007.py
5
007.py
|
@ -12,5 +12,6 @@ def primes(limit):
|
||||||
i = i + 2
|
i = i + 2
|
||||||
return primes
|
return primes
|
||||||
|
|
||||||
print '6th Prime', primes(6)[-1]
|
if __name__ == '__main__':
|
||||||
print '10001st Prime', primes(10001)[-1]
|
print '6th Prime', primes(6)[-1]
|
||||||
|
print '10001st Prime', primes(10001)[-1]
|
||||||
|
|
Loading…
Reference in a new issue