Created
August 21, 2016 03:12
-
-
Save shakemurasan/63c7a1159d589338f606d05c5f32196f to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズル:Q17
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
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def pair2one(num) | |
@count = 0 | |
countup(0, num) # 男子が先頭の場合を計上. | |
countup(1, num) # 女子が先頭の場合を計上. | |
puts @count | |
end | |
def countup(pos, max) | |
@count += 1 # 残り全て男子として計上. | |
((pos + 2)..max).each { |n| countup(n, max) } # 女子の配置. | |
end | |
measure_do { pair2one(30) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment