18 "output_type": "execute_result"
22 "def pentagonal(n)\n",
23 " n * (3 * n - 1) / 2\n",
29 "execution_count": 22,
36 "output_type": "stream",
38 "2167, 1020 -> 5482660\n",
39 "2167, 1020 -> 5482660\n"
44 "pentagonals = Set.new()\n",
50 "best_diff = pentagonal(5000)\n",
53 " pentagonals << pentagonal(sum_index)\n",
54 " ((sum_index/2)...sum_index).each do |j|\n",
55 " k = sum_index - j\n",
56 " diff = pentagonal(j) - pentagonal(k)\n",
57 " if pentagonals.include?(diff) && pentagonals.include?(pentagonal(j)+pentagonal(k))\n",
59 " puts \"#{j}, #{k} -> #{diff}\"\n",
60 " if diff < best_diff\n",
61 " best_diff = diff\n",
69 "puts \"#{best_j}, #{best_k} -> #{best_diff}\""
74 "execution_count": 18,
85 "execution_count": 18,
87 "output_type": "execute_result"
91 "pentagonals.include?(pentagonal(2167))"
96 "execution_count": 23,
107 "execution_count": 23,
109 "output_type": "execute_result"
118 "execution_count": null,
128 "display_name": "Ruby 2.4.0",
133 "file_extension": ".rb",
134 "mimetype": "application/x-ruby",