Created
January 29, 2015 16:50
-
-
Save adambair/ac03cae91c9539cd35aa to your computer and use it in GitHub Desktop.
dsc-february-rompecabeza.rb
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
# Sum of it's parts | |
# | |
# Find a SIX digit number in which the | |
# FIRST digit is ONE more than the THIRD, | |
# the SCOND digit is ONE less than the | |
# FOURTH, the FIFTH digit is ONE less than | |
# the THIRD, and the SIXTH digit is ONE | |
# more than the FOURTH. The sum of the | |
# SECOND and the THIRD digits equal the | |
# FIRST. The sum of all digits is 30. | |
# | |
# http://blog.dollarshaveclub.com/february-rompecabeza/ | |
number = {first:0,second:0,third:0,fourth:0,fifth:0,sixth:0} | |
# Solve for the number not mentioned in the test | |
number[:fourth] = 2 | |
number[:third] = 8 | |
number[:first ] = number[:second] + number[:third] | |
number[:sixth] = number[:fourth] + 1 | |
number[:fifth] = number[:third] - 1 | |
number[:second] = number[:fourth] - 1 | |
number[:first] = number[:third] + 1 | |
puts number[:first] == number[:third] + 1 | |
puts number[:second] == number[:fourth] - 1 | |
puts number[:fifth] == number[:third] - 1 | |
puts number[:sixth] == number[:fourth] + 1 | |
puts number[:first ] == number[:second] + number[:third] | |
sum = number.values.inject(:+) | |
puts number.values.join(', ') | |
puts sum | |
puts sum == 30 | |
answer = number.values.join | |
puts "Answer: #{answer}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment