Last active
November 12, 2015 12:20
-
-
Save kengos/ad1b9f34f2d2779b5d7f to your computer and use it in GitHub Desktop.
浜松ruby#58 その1
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
#!/usr/bin/env ruby | |
class Model | |
attr_accessor :a, :b, :c, :d, :e, :f, :g, :h | |
def attributes(arr) | |
@a = arr[0] | |
@b = arr[1] | |
@c = arr[2] | |
@d = arr[3] | |
@e = arr[4] | |
@f = arr[5] | |
@g = arr[6] | |
@h = arr[7] | |
self | |
end | |
def calc | |
_calc(a, b, c) + _calc(c, d, e) + _calc(e, f, g) + _calc(g, h, a) | |
end | |
def _calc(x, y, z) | |
(100 * x) + (10 * y) + z | |
end | |
def answer | |
b + d + f + h | |
end | |
end | |
arr = (1..8).to_a | |
model = Model.new | |
while model.attributes(arr).calc != 1725 | |
arr.shuffle! | |
end | |
puts model.answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment