Last active
August 26, 2016 13:41
-
-
Save shakemurasan/6e4a77ed9723226a3b9aa3c9fd967609 to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズル:Q18
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' | |
# ------------------------------ | |
ROOT_NUM = [4, 9, 16, 25, 36, 49, 64] | |
def ichigo | |
@result = [] | |
(2..(ROOT_NUM[-1] / 2)).each { |i| search_pair(1, (2..i).to_a, [1]) } | |
p @result | |
end | |
def search_pair(num, array, build) | |
@result = build if (array.size == 0) && ROOT_NUM.include?(num + 1) | |
array.each { |opt| search_pair(opt, array - [opt], build + [opt]) if ROOT_NUM.include?(num + opt) } | |
false | |
end | |
measure_do { ichigo } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment