Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Stegallo committed Dec 8, 2024
1 parent 03bc4a7 commit df62406
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 2 additions & 4 deletions common/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __post_init__(self) -> None:

@staticmethod
def from_input(input_data):
input = [[i for i in chunk] for chunk in input_data]
input = [list(chunk) for chunk in input_data]

grid = {}
for y in input:
Expand All @@ -30,9 +30,7 @@ def from_input(input_data):

def display(self) -> None:
for i in range(self.height):
line = []
for j in range(self.length):
line.append(self.grid[(i, j)])
line = [self.grid[(i, j)] for j in range(self.length)]
print("".join(line))

def items(self):
Expand Down
19 changes: 10 additions & 9 deletions y_2024/day8.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ def _preprocess_input(self):
self.grid = Grid.from_input(self._input_data)
self.grid.display()

def _anti2(self, a, b, i, include) -> list:
x = []
def _get_antinodes(self, a, b, i, include) -> list:
x: list = []
dist = (b[0] - a[0]), (b[1] - a[1])
start = 0 if include else 1
for i in range(start, i):
x.extend(
(
(a[0] - i * (b[0] - a[0]), a[1] - i * (b[1] - a[1])),
(b[0] + i * (b[0] - a[0]), b[1] + i * (b[1] - a[1])),
)
(a[0] - i * dist[0], a[1] - i * dist[1]),
(b[0] + i * dist[0], b[1] + i * dist[1]),
),
)
return x

def _common(self, i, include):
antin = {}
antin = set()
antennas = {k: v for k, v in self.grid.values.items() if k != "."}
for j in antennas.values():
for x in range(len(j)):
for y in range(len(j)):
if j[x] == j[y]:
continue
ants = self._anti2(j[x], j[y], i, include)
ants = self._get_antinodes(j[x], j[y], i, include)
for m in ants:
antin[m] = "O"
antin.add(m)

return sum(bool(antin.get(i)) for i in self.grid.keys())
return sum(bool(i in antin) for i in self.grid.keys())

def _calculate_1(self):
return self._common(2, False)
Expand Down

0 comments on commit df62406

Please sign in to comment.