Tried to solve 55 till 57.

This commit is contained in:
2018-12-24 17:15:19 -05:00
parent 4acfe89f92
commit 147a13a01f
6 changed files with 417 additions and 4 deletions

View File

@@ -13,9 +13,46 @@
"collapsed": true
},
"source": [
"A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.\n",
"A googol ($10^{100}$) is a massive number: one followed by one-hundred zeros; $100^{100}$ is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.\n",
"\n",
"Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?"
"Considering natural numbers of the form, $a^b$, where $a, b < 100$, what is the maximum digital sum?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def get_digit_sum(n):\n",
" s = 0\n",
" while n != 0:\n",
" s += (n % 10)\n",
" n //= 10\n",
" return s\n",
"\n",
"assert(get_digit_sum(1337) == 14)\n",
"assert(get_digit_sum(100**100) == 1)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"972\n"
]
}
],
"source": [
"s = max([get_digit_sum(a**b) for a in range(1, 100) for b in range(1, 100)])\n",
"print(s)"
]
},
{