59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
from tools.aoc import AOCDay
|
|
from tools.coordinate import Square, Coordinate
|
|
from tools.grid import Grid
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(121259, "input3")
|
|
],
|
|
[
|
|
(3, "test_input3"),
|
|
(239, "input3")
|
|
]
|
|
]
|
|
|
|
def getClaims(self) -> list:
|
|
claims = []
|
|
for line in self.getInput():
|
|
_, _, coord, size = line.split()
|
|
x, y = map(int, coord[:-1].split(","))
|
|
dx, dy = map(int, size.split("x"))
|
|
claims.append(Square(Coordinate(x, y), Coordinate(x + dx - 1, y + dy - 1)))
|
|
|
|
return claims
|
|
|
|
def part1(self) -> Any:
|
|
fabric = Grid()
|
|
for claim in self.getClaims():
|
|
fabric.add_shape(claim)
|
|
|
|
count = 0
|
|
for x in fabric.values():
|
|
if x > 1:
|
|
count += 1
|
|
|
|
return count
|
|
|
|
def part2(self) -> Any:
|
|
claims = self.getClaims()
|
|
|
|
for i, claim in enumerate(claims):
|
|
inter = False
|
|
for claim2 in claims:
|
|
if claim2 == claim:
|
|
continue
|
|
if claim.intersection(claim2):
|
|
inter = True
|
|
break
|
|
|
|
if not inter:
|
|
return i + 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2018, 3)
|
|
day.run(verbose=True)
|