Add files via upload

This commit is contained in:
Peter Norvig 2024-12-14 12:09:42 -08:00 committed by GitHub
parent edb71ac930
commit d48f47b2f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 94444 additions and 180 deletions

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@ -120,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@ -168,14 +168,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
@ -207,6 +200,12 @@
" f' WRONG; expected answer is {self.solution}')\n",
" return f'Puzzle {self.puzzle:4.1f}: {secs} seconds, answer {self.got:<15}{comment}'\n",
"\n",
"def report(answers):\n",
" for d in sorted(answers):\n",
" print(answers[d])\n",
" secs = sum(answers[d].secs for d in answers)\n",
" print(f'\\nTotal time {secs:.4f} seconds, Mean time {secs/len(answers):.4f} seconds')\n",
"\n",
"def test_answer():\n",
" print(answer(0.1, unknown))\n",
" print(answer(0.2, 2**39, lambda: 2**39))\n",
@ -225,21 +224,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'defaultdict' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mmultimap\u001b[39;00m(\u001b[43mdefaultdict\u001b[49m):\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124;03m\"\"\"A mapping of {key: [val1, val2, ...]}.\"\"\"\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, pairs:Iterable[\u001b[38;5;28mtuple\u001b[39m]\u001b[38;5;241m=\u001b[39m(), symmetric\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m):\n",
"\u001b[0;31mNameError\u001b[0m: name 'defaultdict' is not defined"
]
}
],
"outputs": [],
"source": [
"class multimap(defaultdict):\n",
" \"\"\"A mapping of {key: [val1, val2, ...]}.\"\"\"\n",
@ -371,7 +358,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@ -438,7 +425,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
@ -494,7 +481,11 @@
"\n",
"def taxi_distance(p: Point, q: Point) -> int:\n",
" \"\"\"Manhattan (L1) distance between two 2D Points.\"\"\"\n",
" return abs(p[0] - q[0]) + abs(p[1] - q[1])"
" return abs(p[0] - q[0]) + abs(p[1] - q[1])\n",
"\n",
"def distance_squared(p: Point, q: Point) -> float:\n",
" \"\"\"Square of the Euclidean (L2) distance between two 2D points.\"\"\"\n",
" return (p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2"
]
},
{
@ -517,7 +508,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
@ -621,7 +612,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
@ -649,7 +640,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
@ -726,7 +717,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
@ -755,7 +746,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
@ -770,7 +761,7 @@
},
{
"cell_type": "code",
"execution_count": 113,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
@ -785,7 +776,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
@ -806,7 +797,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [