Skip to content

Instantly share code, notes, and snippets.

@masui
Created May 25, 2015 15:44
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 masui/b688b4275f5d59fea6ec to your computer and use it in GitHub Desktop.
Save masui/b688b4275f5d59fea6ec to your computer and use it in GitHub Desktop.
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