Add files via upload

This commit is contained in:
Peter Norvig 2024-12-17 23:17:19 -08:00 committed by GitHub
parent 0f16deb1a9
commit 268e1edcdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 459 additions and 170 deletions

File diff suppressed because it is too large Load Diff

View File

@ -198,7 +198,7 @@
" comment = (f'' if self.got == unknown else\n", " comment = (f'' if self.got == unknown else\n",
" f' ok' if self.ok else \n", " f' ok' if self.ok else \n",
" f' WRONG; expected answer is {self.solution}')\n", " f' WRONG; expected answer is {self.solution}')\n",
" return f'Puzzle {self.puzzle:4.1f}: {secs} seconds, answer {self.got:<15}{comment}'\n", " return f'Puzzle {self.puzzle:4.1f}: {secs} seconds, answer {self.got:<17}{comment}'\n",
"\n", "\n",
"def summary(answers):\n", "def summary(answers):\n",
" \"\"\"Print a report that summarizes the answers.\"\"\"\n", " \"\"\"Print a report that summarizes the answers.\"\"\"\n",
@ -554,7 +554,8 @@
" 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",
" return [add2(point, Δ) for Δ in self.directions \n", " return [add2(point, Δ) for Δ in self.directions \n",
" if add2(point, Δ) in self or self.default not in (KeyError, None)]\n", " if (add2(point, Δ) in self) \n",
" or (self.default not in (KeyError, None))]\n",
" \n", " \n",
" def neighbor_contents(self, point) -> Iterable:\n", " def neighbor_contents(self, point) -> Iterable:\n",
" \"\"\"The contents of the neighboring points.\"\"\"\n", " \"\"\"The contents of the neighboring points.\"\"\"\n",
@ -664,8 +665,7 @@
"class GridProblem(SearchProblem):\n", "class GridProblem(SearchProblem):\n",
" \"\"\"Problem for searching a grid from a start to a goal location.\n", " \"\"\"Problem for searching a grid from a start to a goal location.\n",
" A state is just an (x, y) location in the grid.\"\"\"\n", " A state is just an (x, y) location in the grid.\"\"\"\n",
" def actions(self, loc): return self.grid.neighbors(loc)\n", " def actions(self, pos): return [p for p in self.grid.neighbors(pos) if self.grid[pos] != '#']\n",
" def result(self, loc1, loc2): return loc2\n",
" def h(self, node): return taxi_distance(node.state, self.goal) \n", " def h(self, node): return taxi_distance(node.state, self.goal) \n",
"\n", "\n",
"class Node:\n", "class Node:\n",