Created
July 23, 2012 23:57
-
-
Save cyrusstoller/3167034 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
# Code to solve the circle hackathon invite challenge http://discovercircle.com/hackathon | |
def main | |
# seven digit number where number is ABCDEFG | |
# A*B*C = C*D*E = E*F*G | |
# A,B,C,D,E,F,G can't be 0 | |
# can't use 5 or 7 since they're prime | |
possible_digits = [1,2,3,4,6,8,9] | |
prime_factorization = [[1],[2],[3],[2,2],[2,3],[2,2,2],[3,3]] | |
prime_factorization.permutation(7).each do |iter| | |
val1 = product_of_array(iter[0] + iter[1] + iter[2]) | |
val2 = product_of_array(iter[2] + iter[3] + iter[4]) | |
val3 = product_of_array(iter[4] + iter[5] + iter[6]) | |
if val1 == val2 and val2 == val3 | |
puts product_of_array(iter[3]) | |
return | |
end | |
end | |
return nil | |
end | |
def product_of_array(arr) | |
return arr.reduce(1) do |product, value| | |
product * value | |
end | |
end | |
if __FILE__ == $PROGRAM_NAME | |
main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment