"The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be $1 + 2 + 3 + 4 + 5 + 6 + 7 = 28$. The first ten terms would be:\n",
"This are the prime numbers related functions we already now. Now we implement a group function, the product function we already know, and based on that the algorithm to get the number of divisors mentioned above."
" # get the length of each group and increment it by one\n",
" ps = map(lambda x: len(x) + 1, ps)\n",
" # get the product of all values\n",
" return product(ps)\n",
" \n",
"assert(get_number_of_divisors(28) == 6)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we are ready to do another brute force attempt."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"76576500\n"
]
}
],
"source": [
"ts = triangle_number_generator_function()\n",
"for t in ts:\n",
" if get_number_of_divisors(t) > 500:\n",
" print(t)\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the only question is why this crazy algorithm works. Okay, I got it with the help of [this](https://www.math.upenn.edu/~deturck/m170/wk2/numdivisors.html) page. The problem is actually an instance of the multiplication principle for counting things. Each prime can be used to calculate (n + 1) other divisors. The incrementation by one is required because we can also choose to not use a certain prime. Of course, to get the potential combinations we have to get the product of the potential divisors for all primes. The web page explains it better. The only question is whether I came up with this algorithm myself back then."