Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:25
Show Gist options
  • Save gavinsykes/fc5f230bcd5f052c64499df9f549ca2c to your computer and use it in GitHub Desktop.
Save gavinsykes/fc5f230bcd5f052c64499df9f549ca2c to your computer and use it in GitHub Desktop.
import argparse
import sys
sys.path.append('/home/gavin/Documents/Git Repositories/project-euler')
import pyfuncs
challenge = 'Find the sum of all the multiples of 3 or 5 below {}:'
parser = argparse.ArgumentParser(description = 'Find the sum of all the multiples of 3 or 5 below a given number.')
parser.add_argument('--num', default = 1000, type = int, help = 'Insert the number here, it must be a positive integer. It defaults to 1000 to correspond with the Project Euler Problem at https://projecteuler.net/problem=1')
x = parser.parse_args().num
if ( (x < 1) and (not isinstance(x, int)) ):
raise Exception('You entered {}, which is neither an integer nor larger than 1!'.format(x))
if (x < 1):
raise Exception('You entered {}, which is less than 1, please try a positive integer.'.format(x))
if (not isinstance(x,int)):
raise Exception('You entered {}, which is not an integer, please try a positive integer.'.format(x))
def euler_1(n):
result = 0
x = n/3
y = n/5
for i in range (1,int(x)):
result += 3*i
for i in range (1,int(y)):
if (5*i % 3 != 0):
result += 5*i
return result
pyfuncs.fullprint(challenge,euler_1,x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment