Skip to content

Instantly share code, notes, and snippets.

@carlosonunez
Created October 6, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosonunez/d9afdf220710ae37f5af to your computer and use it in GitHub Desktop.
Save carlosonunez/d9afdf220710ae37f5af to your computer and use it in GitHub Desktop.
import re
def SumPrimeFactors(num):
def ValidateRuthAaronPairs():
number_of_pairs = int(raw_input("Number of pairs:"))
pairs = []
while (number_of_pairs > 0):
this_pair = raw_input("Pair: ")
if re.match("^\(\d+,\d+\)$",this_pair is not None:
numbers = re.findall("\d+",this_pair)
first_number = int(numbers[0])
second_number = int(numbers[1])
if second_number-first_number == 1:
pairs.append([first_number,second_number])
else
raise Exception(first_number," and ",second_number," do not form a Ruth-Aaron pair.")
else
raise Exception("The format for this pair is invalid: ",this_pair)
number_of_pairs--
for pair in pairs:
first_number = pair[0]
second_number = pair[1]
print "(",first_number,",",second_number,") ",
print "VALID" if SumPrimeFactors(first_number) == SumPrimeFactors(second_number) else print "NOT VALID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment