75 lines
1.6 KiB
Plaintext
75 lines
1.6 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "d5ba1893",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# [Pandigital Multiples](https://projecteuler.net/problem=38)\n",
|
||
|
"\n",
|
||
|
"Any number with five or more digits will have a concatenated product with more than 9 digits. Therefore we only need to check numbers with less than five digits."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"id": "ffea7112",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"932718654"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from itertools import count\n",
|
||
|
"\n",
|
||
|
"def is_pandigital(s):\n",
|
||
|
" return ''.join(sorted(s)) == \"123456789\"\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"pandigitals = set()\n",
|
||
|
"for k in range(1, 10000):\n",
|
||
|
" s = \"\"\n",
|
||
|
" for n in count(1):\n",
|
||
|
" s += str(k * n)\n",
|
||
|
" if len(s) >= 9:\n",
|
||
|
" break\n",
|
||
|
" \n",
|
||
|
" if is_pandigital(s):\n",
|
||
|
" pandigitals.add(int(s))\n",
|
||
|
"\n",
|
||
|
" \n",
|
||
|
"max(pandigitals)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "SageMath 9.5",
|
||
|
"language": "sage",
|
||
|
"name": "sagemath"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.11.2"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|