数学パズルQ15
def search(countries, prev, depth) # 前の国名に続く国の一覧を取得 next_countries = countries.select { |c| c[0] == prev[-1].upcase } return depth if next_countries.size == 0 # 続く国がある場合、その国を除いて再帰的に探索 next_countries.reduce(0) { |acc, c| [acc, search(countries - [c], c, depth + 1)].max } end