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:
Correl Roush 2010-04-12 15:53:08 +00:00
parent eecb37127f
commit 715e24dcf3
4 changed files with 11 additions and 8 deletions

2
004.py
View file

@ -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()

2
005.py
View file

@ -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)

2
006.py
View file

@ -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
if __name__ == '__main__':
squarediff(10) squarediff(10)
squarediff(100) squarediff(100)

1
007.py
View file

@ -12,5 +12,6 @@ def primes(limit):
i = i + 2 i = i + 2
return primes return primes
if __name__ == '__main__':
print '6th Prime', primes(6)[-1] print '6th Prime', primes(6)[-1]
print '10001st Prime', primes(10001)[-1] print '10001st Prime', primes(10001)[-1]