Add some checks to day1
This commit is contained in:
parent
1547b74037
commit
ae9a02410b
32
day1/run.py
32
day1/run.py
|
@ -15,13 +15,21 @@ class SplitLists:
|
|||
self.list1, self.list2 = zip(*[val.split() for val in input.split("\n") if val])
|
||||
|
||||
def __str__(self) -> str:
|
||||
part1 = 0
|
||||
return f"Part 1 = {self._part1}, Part 2 = {self._part2}"
|
||||
|
||||
@property
|
||||
def _part1(self) -> int:
|
||||
outp = 0
|
||||
for val in self.distances():
|
||||
part1 += val
|
||||
part2 = 0
|
||||
outp += val
|
||||
return outp
|
||||
|
||||
@property
|
||||
def _part2(self) -> int:
|
||||
outp = 0
|
||||
for val, occ in zip(self.list1, self.occurances()):
|
||||
part2 += int(val) * occ
|
||||
return f"Part1: {part1}\nPart2: {part2}"
|
||||
outp += int(val) * occ
|
||||
return outp
|
||||
|
||||
def distances(self) -> List[int]:
|
||||
return [
|
||||
|
@ -33,12 +41,10 @@ class SplitLists:
|
|||
return [self.list2.count(key) for key in self.list1]
|
||||
|
||||
|
||||
def main(*args, **kwargs) -> None:
|
||||
example = SplitLists(input=EXAMPLE)
|
||||
print(example)
|
||||
with open("input.txt", "r") as f:
|
||||
print(SplitLists(input=f.read()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
example = SplitLists(input=EXAMPLE)
|
||||
print("EXAMPLE:\n", example)
|
||||
assert example._part1 == 11
|
||||
assert example._part2 == 31
|
||||
with open("input.txt", "r") as f:
|
||||
print("Puzzle:\n", SplitLists(input=f.read()))
|
||||
|
|
Loading…
Reference in a new issue