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

4
004.py
View file

@ -7,5 +7,5 @@ def palindrome():
palindromes[i * ii] = [i, ii]
p = sorted(palindromes.keys(), reverse=True)[0]
print 'Palindrome: {0}x{1}: {2}'.format(palindromes[p][0], palindromes[p][1], p)
palindrome()
if __name__ == '__main__':
palindrome()

4
005.py
View file

@ -8,5 +8,5 @@ def divisible(n):
break
if ii == 1:
return x
print 'Smallest number: ', divisible(20)
if __name__ == '__main__':
print 'Smallest number: ', divisible(20)

6
006.py
View file

@ -1,9 +1,11 @@
def squarediff(n):
print 'Checking for n =', n
sumofsquares = sum([x**2 for x in range(n + 1)])
print 'Sum of squares', sumofsquares
squareofsum = sum(range(n + 1))**2
print 'Square of sum', squareofsum
print 'Difference', squareofsum - sumofsquares
squarediff(10)
squarediff(100)
if __name__ == '__main__':
squarediff(10)
squarediff(100)

5
007.py
View file

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