Created
October 6, 2015 22:18
-
-
Save carlosonunez/d9afdf220710ae37f5af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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