diff --git a/2023/day16.py b/2023/day16.py index a007b63..b7bc19b 100644 --- a/2023/day16.py +++ b/2023/day16.py @@ -29,11 +29,11 @@ def simulate_light(grid, start, initial_d): if grid[photon] == '.': photons.append((photon + d, d)) elif grid[photon] == '/': - nd = [W, E, S, N][[N, S, E, W].index(d)] - photons.append((photon + nd, nd)) + # ~d takes N <-> E and S <-> W + photons.append((photon + ~d, ~d)) elif grid[photon] == '\\': - nd = [E, W, N, S][[N, S, E, W].index(d)] - photons.append((photon + nd, nd)) + # -~d takes N <-> W and S <-> E + photons.append((photon + -~d, -~d)) elif grid[photon] == '|': if d in (N, S): photons.append((photon + d, d)) diff --git a/2023/utils.py b/2023/utils.py index 5b6441a..923307c 100644 --- a/2023/utils.py +++ b/2023/utils.py @@ -466,6 +466,9 @@ class Point: def __lt__(self, other): return self.length < other.length + def __invert__(self): + return Point(-self.y, -self.x) + def __str__(self): return "({}, {})".format(self.x, self.y)