Finished 32 in ipython.
This commit is contained in:
@@ -15,6 +15,13 @@
|
||||
"HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We start by thinking about how many digits are used for multiplicand/multiplier/product. Obviously, the product must have more then three digits. Can it have more then 4 digits? Obviously it can because then there are only four digits for multiplicand and multiplier which is always smaller than ten thousand. So our product must be in the form $12 \\cdot 345 = 5789$. This makes the rest very easy in Python."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
@@ -23,30 +30,36 @@
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "AssertionError",
|
||||
"evalue": "",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m<ipython-input-1-8e612cf3c592>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0ms\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m45228\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[1;31mAssertionError\u001b[0m: "
|
||||
]
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"45228"
|
||||
]
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"s = 0\n",
|
||||
"assert(s == 45228)"
|
||||
"from itertools import permutations\n",
|
||||
"\n",
|
||||
"def is_solution(s):\n",
|
||||
" a, b, c = int(s[0:2]), int(s[2:5]), int(s[5:])\n",
|
||||
" if a * b == c:\n",
|
||||
" return c\n",
|
||||
" a, b, c = int(s[0:1]), int(s[1:5]), int(s[5:]) \n",
|
||||
" if a * b == c:\n",
|
||||
" return c\n",
|
||||
" return 0\n",
|
||||
"\n",
|
||||
"assert(is_solution(\"391867254\") == 7254)\n",
|
||||
"assert(is_solution(\"391867245\") == 0)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"s = sum(set([is_solution(\"\".join(p)) for p in permutations(\"123456789\")]))\n",
|
||||
"assert(s == 45228)\n",
|
||||
"s"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in New Issue
Block a user