Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
1時間以内に解けなければプログラマ失格となってしまう5つの問題
#
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions
#
def power(level, a, &block)
if level > 0 then
['+', '-', ''].each { |op|
a[level-1] = op
power level-1, a, &block
}
else
yield a
end
end
power(8,[]){ |arg|
s = '1'
(2..9).each { |i|
s += arg[i-2]
s += i.to_s
}
val = eval(s)
puts "#{s} ==> #{val}" if val == 100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.