Add files via upload

This commit is contained in:
Peter Norvig 2025-12-20 16:52:30 -08:00 committed by GitHub
parent 85f08d9621
commit 69a2b1f887
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 371 additions and 203 deletions

File diff suppressed because it is too large Load Diff

149
ipynb/lander-parkin66.ipynb Normal file
View File

@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "4c2c6cf3-da5e-4fef-b37b-cbed145f4eea",
"metadata": {},
"source": [
"[COUNTEREXAMPLE TO EULER'S CONJECTURE ON SUMS OF LIKE POWERS](https://projecteuclid.org/journals/bulletin-of-the-american-mathematical-society-new-series/volume-72/issue-6/Counterexample-to-Eulers-conjecture-on-sums-of-like-powers/bams/1183528522.full)\n",
"\n",
"![](https://i.sstatic.net/VQL6D.png)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "7de18ad5-b328-4618-911d-32c61ddab13d",
"metadata": {},
"outputs": [],
"source": [
"def sum_of_powers(M: int, n=5) -> list[tuple[int]]:\n",
" \"\"\"Return all (a, b, c, d, e), all < M, such that a^n + b^n + c^n + d^n = e^n.\n",
" This is O(M^3) in time and O(M^2) in space.\"\"\"\n",
" table = {a ** n + b ** n: (a, b)\n",
" for (a, b) in combinations(range(M), 2)}\n",
" results = []\n",
" for (c, d, e) in combinations(range(M), 3):\n",
" an_plus_bn = e ** n - (c ** n + d ** n)\n",
" if an_plus_bn in table:\n",
" a, b = table[an_plus_bn]\n",
" if a <= b <= c <= d: # Don't want duplicates\n",
" results.append((a, b, c, d, e))\n",
" return results"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "00dc3732-ed29-4137-a3f8-fc7921e28d08",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(27, 84, 110, 133, 144)]"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum_of_powers(150)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "8c603613-b561-4a97-9779-c4d94269331a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 3.39 s, sys: 5.23 ms, total: 3.4 s\n",
"Wall time: 3.4 s\n"
]
},
{
"data": {
"text/plain": [
"[[27, 84, 110, 133, 144], [54, 168, 220, 266, 288]]"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%time sum_of_powers(300)"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "6e9de2d8-abf2-482d-adeb-c2ac01d10b4e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 1min 9s, sys: 227 ms, total: 1min 9s\n",
"Wall time: 1min 11s\n"
]
},
{
"data": {
"text/plain": [
"[[27, 84, 110, 133, 144],\n",
" [54, 168, 220, 266, 288],\n",
" [81, 252, 330, 399, 432],\n",
" [108, 336, 440, 532, 576],\n",
" [135, 420, 550, 665, 720],\n",
" [162, 504, 660, 798, 864]]"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%time sum_of_powers(1000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b0ee9d9-d38d-4a63-8ccf-7baed27967f1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}