Created
November 11, 2015 11:12
-
-
Save k4200/71dc5e216adf3cb275b0 to your computer and use it in GitHub Desktop.
hamamatsu.rb #58 のお題を解いた(Ruby)
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
# http://jukensansu.cocolog-nifty.com/planet/2015/11/post-0b4b.html | |
# 総当りで | |
# Rubyはあまり得意でない | |
def array_to_digit(ary) | |
return ary[0] * 100 + ary[1] * 10 + ary[2] | |
end | |
def calc_sum(ary) | |
return array_to_digit(ary[0, 3]) + array_to_digit(ary[2, 3]) + array_to_digit(ary[4, 3]) + array_to_digit(ary[6, 2] + ary[0, 1]) | |
end | |
all_arrays = (1..8).to_a.permutation | |
for ary in all_arrays | |
s = calc_sum(ary) | |
if s == 1725 | |
p ary[1], ary[3], ary[5], ary[7] | |
break | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment