Add files via upload

This commit is contained in:
Peter Norvig authored and GitHub committed 2024-12-13 10:43:24 -08:00
1 parent 9de830b2d8
commit edb71ac930
2 files changed
+507 -193

No files matched your search

+496 -191
View File
File diff suppressed because it is too large. Load diff
+11 -2
View File
@@ -25,7 +25,7 @@
"from itertools import count as count_from, product as cross_product\n",
"from typing import *\n",
"from statistics import mean, median\n",
"from math import ceil, floor, factorial, gcd, log, log2, log10, sqrt, inf\n",
"from math import ceil, floor, factorial, gcd, log, log2, log10, sqrt, inf, atan2\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import ast\n",
@@ -488,6 +488,10 @@
" \"\"\"Specialized version of point addition for 2D Points only. Faster.\"\"\"\n",
" return (p[0] + q[0], p[1] + q[1])\n",
"\n",
"def sub2(p: Point, q: Point) -> Point: \n",
" \"\"\"Specialized version of point subtraction for 2D Points only. Faster.\"\"\"\n",
" return (p[0] - q[0], p[1] - q[1])\n",
"\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])"
@@ -552,6 +556,11 @@
" return (0 <= X_(point) < X_(self.size) and\n",
" 0 <= Y_(point) < Y_(self.size))\n",
"\n",
" def follow_line(self, start: Point, direction: Vector) -> Iterable[Point]:\n",
" while self.in_range(start):\n",
" yield start\n",
" start = add2(start, direction)\n",
"\n",
" def copy(self): \n",
" return Grid(self, directions=self.directions, skip=self.skip, default=self.default)\n",
" \n",
@@ -878,7 +887,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.12.7"
}
},
"nbformat": 4,