4 "cell_type": "markdown",
7 "Note that the _n_ th hexagonal number is the $2(n-1)+1$th triangle number. Therefore, we can find a number that is both pentagonal and hexagonal.\n",
9 "The _n_ hexagonal number is never smaller than the _n_ th pentagonal number, so the idea is to generate the next hexagonal number, then all pentagonal numbers until we find one that is larger than the largest hexagonal one found so far."
27 "output_type": "execute_result"
31 "def pentagonal(n)\n",
32 " n * (3 * n - 1) / 2\n",
51 "output_type": "execute_result"
62 "execution_count": 11,
69 "output_type": "stream",
71 "31977, 27693, 1533776805\n"
82 " while pentagonal(p_i) < hexagonal(h_i)\n",
85 " if pentagonal(p_i) == hexagonal(h_i)\n",
86 " puts \"#{p_i}, #{h_i}, #{pentagonal(p_i)}\"\n",
95 "execution_count": null,
105 "display_name": "Ruby 2.4.0",
110 "file_extension": ".rb",
111 "mimetype": "application/x-ruby",