From 715e24dcf3500da0c077fb2056d05ef4300bead8 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 12 Apr 2010 15:53:08 +0000 Subject: [PATCH] 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 --- 004.py | 4 ++-- 005.py | 4 ++-- 006.py | 6 ++++-- 007.py | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/004.py b/004.py index d754d22..3ee4745 100644 --- a/004.py +++ b/004.py @@ -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() diff --git a/005.py b/005.py index f4674a4..4f7318d 100644 --- a/005.py +++ b/005.py @@ -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) diff --git a/006.py b/006.py index 91c8006..1470d52 100644 --- a/006.py +++ b/006.py @@ -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) diff --git a/007.py b/007.py index 3129d24..0af7cd4 100644 --- a/007.py +++ b/007.py @@ -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]