Add files via upload

This commit is contained in:
Peter Norvig 2024-12-28 23:21:05 -08:00 committed by GitHub
parent 9a4949ee01
commit af672ed94a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 525 additions and 355 deletions

File diff suppressed because it is too large Load Diff

View File

@ -67,15 +67,28 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"ename": "NameError",
"evalue": "name 'whole' 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[7], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m lines \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mstr\u001b[39m\u001b[38;5;241m.\u001b[39msplitlines \u001b[38;5;66;03m# By default, split input text into lines\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mparagraphs\u001b[39m(text): \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSplit text into paragraphs\u001b[39m\u001b[38;5;124m\"\u001b[39m; \u001b[38;5;28;01mreturn\u001b[39;00m text\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 6\u001b[0m whole\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mparse\u001b[39m(day_or_text:Union[\u001b[38;5;28mint\u001b[39m, \u001b[38;5;28mstr\u001b[39m], parser\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mstr\u001b[39m, sections\u001b[38;5;241m=\u001b[39mlines, show\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m8\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mtuple\u001b[39m:\n\u001b[1;32m 9\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Split the input text into `sections`, and apply `parser` to each.\u001b[39;00m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124;03m The first argument is either the text itself, or the day number of a text file.\"\"\"\u001b[39;00m\n",
"\u001b[0;31mNameError\u001b[0m: name 'whole' is not defined"
]
}
],
"source": [ "source": [
"current_year = 2023 # Subdirectory name for input files\n", "current_year = 2023 # Subdirectory name for input files\n",
"\n", "\n",
"lines = str.splitlines # By default, split input text into lines\n", "lines = str.splitlines # By default, split input text into lines\n",
"\n", "\n",
"def paragraphs(text): \"Split text into paragraphs\"; return text.split('\\n\\n')\n", "def paragraphs(text): \"Split text into paragraphs\"; return text.split('\\n\\n')\n",
"def whole(text): \"The whole text\"; return [text]\n",
"\n", "\n",
"def parse(day_or_text:Union[int, str], parser=str, sections=lines, show=8) -> tuple:\n", "def parse(day_or_text:Union[int, str], parser=str, sections=lines, show=8) -> tuple:\n",
" \"\"\"Split the input text into `sections`, and apply `parser` to each.\n", " \"\"\"Split the input text into `sections`, and apply `parser` to each.\n",
@ -541,12 +554,16 @@
" 0 <= Y_(point) < Y_(self.size))\n", " 0 <= Y_(point) < Y_(self.size))\n",
"\n", "\n",
" def follow_line(self, start: Point, direction: Vector) -> Iterable[Point]:\n", " def follow_line(self, start: Point, direction: Vector) -> Iterable[Point]:\n",
" \"\"\"All points from start going in direction, until the edge of the grid.\"\"\"\n",
" while self.in_range(start):\n", " while self.in_range(start):\n",
" yield start\n", " yield start\n",
" start = add(start, direction)\n", " start = add(start, direction)\n",
"\n", "\n",
" def copy(self): \n", " def copy(self, updates={}): \n",
" return Grid(self, directions=self.directions, skip=self.skip, default=self.default)\n", " \"\"\"Make a copy of this grid, and optionally update some positions with new values.\"\"\"\n",
" grid = Grid(self, directions=self.directions, skip=self.skip, default=self.default)\n",
" grid.update(updates)\n",
" return grid\n",
" \n", " \n",
" def neighbors(self, point) -> List[Point]:\n", " def neighbors(self, point) -> List[Point]:\n",
" \"\"\"Points on the grid that neighbor `point`.\"\"\"\n", " \"\"\"Points on the grid that neighbor `point`.\"\"\"\n",