My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement bitwise inversion on Point class

This maps `Point(x, y)` to `Point(-y, -x)`, allowing for easier
manipulation of direction mappings amongst other things. I am almost
certainly going to confuse myself and think it returns `Point(-y, x)`.

+7 -4
+4 -4
2023/day16.py
··· 29 29 if grid[photon] == '.': 30 30 photons.append((photon + d, d)) 31 31 elif grid[photon] == '/': 32 - nd = [W, E, S, N][[N, S, E, W].index(d)] 33 - photons.append((photon + nd, nd)) 32 + # ~d takes N <-> E and S <-> W 33 + photons.append((photon + ~d, ~d)) 34 34 elif grid[photon] == '\\': 35 - nd = [E, W, N, S][[N, S, E, W].index(d)] 36 - photons.append((photon + nd, nd)) 35 + # -~d takes N <-> W and S <-> E 36 + photons.append((photon + -~d, -~d)) 37 37 elif grid[photon] == '|': 38 38 if d in (N, S): 39 39 photons.append((photon + d, d))
+3
2023/utils.py
··· 466 466 def __lt__(self, other): 467 467 return self.length < other.length 468 468 469 + def __invert__(self): 470 + return Point(-self.y, -self.x) 471 + 469 472 def __str__(self): 470 473 return "({}, {})".format(self.x, self.y) 471 474