Skip to content

Instantly share code, notes, and snippets.

@shakemurasan
Last active August 26, 2016 13:41
Show Gist options
  • Save shakemurasan/6e4a77ed9723226a3b9aa3c9fd967609 to your computer and use it in GitHub Desktop.
Save shakemurasan/6e4a77ed9723226a3b9aa3c9fd967609 to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズル:Q18
# -- 処理時間計測の自作ライブラリ --
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