Compare commits
No commits in common. "a5f37defcede65974345f72c9236b5ade31964b3" and "e5f3e9015fc839c9c3de630abc2b5a2a21f6bed7" have entirely different histories.
a5f37defce
...
e5f3e9015f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
__pycache__
|
||||
@ -11,8 +11,8 @@ y_bound: int = len(data)
|
||||
x_bound: int = len(data[0].strip())
|
||||
|
||||
for y, line in enumerate(data):
|
||||
for x, char in enumerate(line.strip()):
|
||||
if char not in ['.']:
|
||||
for x, char in enumerate(line):
|
||||
if char not in ['.', '\n']:
|
||||
if char not in groups:
|
||||
groups[char] = [Vector(x, y)]
|
||||
else:
|
||||
@ -22,15 +22,6 @@ for y, line in enumerate(data):
|
||||
def in_bounds(v: Vector) -> bool:
|
||||
return v.x >= 0 and v.x < x_bound and v.y >= 0 and v.y < y_bound
|
||||
|
||||
def print_nodes(antinodes: list[Vector]) -> None:
|
||||
datac = data.copy()
|
||||
for antinode in antinodes:
|
||||
datac[antinode.y] = datac[antinode.y][:antinode.x] + '#' + datac[antinode.y][antinode.x + 1:]
|
||||
|
||||
for line in datac:
|
||||
print(line, end='')
|
||||
print()
|
||||
|
||||
antinodes = []
|
||||
for char, group in groups.items():
|
||||
for i, A in enumerate(group):
|
||||
@ -45,33 +36,13 @@ for char, group in groups.items():
|
||||
if antinode_pos2 not in antinodes and in_bounds(antinode_pos2):
|
||||
antinodes.append(antinode_pos2)
|
||||
|
||||
print_nodes(antinodes)
|
||||
for antinode in antinodes:
|
||||
data[antinode.y] = data[antinode.y][:antinode.x] + '#' + data[antinode.y][antinode.x + 1:]
|
||||
|
||||
print(f'Part 1: {len(antinodes)}')
|
||||
for line in data:
|
||||
print(line, end='')
|
||||
|
||||
print(f'\nPart 1: {len(antinodes)}')
|
||||
|
||||
# Part 2
|
||||
antinodes = []
|
||||
|
||||
for char, group in groups.items():
|
||||
for i, A in enumerate(group):
|
||||
for B in group[i + 1:]:
|
||||
|
||||
dist = B - A
|
||||
antinode_pos = A + dist
|
||||
while in_bounds(antinode_pos):
|
||||
if antinode_pos not in antinodes:
|
||||
antinodes.append(antinode_pos)
|
||||
|
||||
antinode_pos += dist
|
||||
|
||||
dist = dist.inverse()
|
||||
antinode_pos = B + dist
|
||||
while in_bounds(antinode_pos):
|
||||
if antinode_pos not in antinodes:
|
||||
antinodes.append(antinode_pos)
|
||||
|
||||
antinode_pos += dist
|
||||
|
||||
print_nodes(antinodes)
|
||||
|
||||
print(f'Part 2: {len(antinodes)}')
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
T.........
|
||||
...T......
|
||||
.T........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
@ -19,9 +19,6 @@ class Vector:
|
||||
def abs(self) -> Self:
|
||||
return Vector(abs(self.x), abs(self.y))
|
||||
|
||||
def inverse(self) -> Self:
|
||||
return Vector(-self.x, -self.y)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.x}, {self.y}'
|
||||
|
||||
@ -30,3 +27,5 @@ class Vector:
|
||||
|
||||
def distance(self, other: Self) -> int:
|
||||
return math.sqrt((other.x - self.x)**2 + (other.y - self.y)**2)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user