Skip to content

Instantly share code, notes, and snippets.

@existentializm
Created November 15, 2019 20:34
Show Gist options
  • Select an option

  • Save existentializm/8b7ec35be900d929a394a73274d1b3ea to your computer and use it in GitHub Desktop.

Select an option

Save existentializm/8b7ec35be900d929a394a73274d1b3ea to your computer and use it in GitHub Desktop.
BSides Detroit Math Challenge
# What is the sum of primes between 7000 and 1000000 that starts with a 7 or ends with a 3?
primesList=[]
startSeven=[]
endThree=[]
lower = 7000
upper = 1000000
for num in range(lower, upper + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
# Get a list of all the prime numbers in the range
else:
primesList.append(num)
# Get a list of all numbers that start with 7
for item in primesList[0:-1]:
if str(item).startswith('7'):
startSeven.append(item)
else:
break
# Get a list of all numbers that end with a 3
for item in primesList[0:-1]:
if str(item).endswith('3'):
endThree.append(item)
else:
break
# Join the two lists
joinedList = startSeven + endThree
# Remove duplicates
cleanList = list(dict.fromkeys(joinedList))
# Get the sum of all the numbers in the list
total = sum(cleanList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment