Skip to content

Instantly share code, notes, and snippets.

@cyrusstoller
Created July 23, 2012 23:57
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 cyrusstoller/3167034 to your computer and use it in GitHub Desktop.
Save cyrusstoller/3167034 to your computer and use it in GitHub Desktop.
# 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