generated from public/aoc_template
day1
This commit is contained in:
parent
1c5377d765
commit
9a41c6d42a
39
day01.py
Normal file
39
day01.py
Normal file
@ -0,0 +1,39 @@
|
||||
from collections import Counter
|
||||
from tools.aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(11, "input1_test"),
|
||||
(2196996, "input1"),
|
||||
],
|
||||
[
|
||||
(31, "input1_test"),
|
||||
(23655822, "input1"),
|
||||
]
|
||||
]
|
||||
|
||||
def parse_input(self) -> (list, list):
|
||||
lefts, rights = [], []
|
||||
for line in self.getInput():
|
||||
left, right = map(int, line.split())
|
||||
lefts.append(left)
|
||||
rights.append(right)
|
||||
|
||||
return list(sorted(lefts)), list(sorted(rights))
|
||||
|
||||
def part1(self) -> Any:
|
||||
lefts, rights = self.parse_input()
|
||||
return sum(abs(lefts[x] - rights[x]) for x in range(len(lefts)))
|
||||
|
||||
def part2(self) -> Any:
|
||||
lefts, rights = self.parse_input()
|
||||
rights = Counter(rights)
|
||||
return sum(num * rights[num] for num in lefts)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
day = Day(2024, 1)
|
||||
day.run(verbose=True)
|
||||
1000
inputs/input1
Normal file
1000
inputs/input1
Normal file
File diff suppressed because it is too large
Load Diff
6
inputs/input1_test
Normal file
6
inputs/input1_test
Normal file
@ -0,0 +1,6 @@
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
Loading…
Reference in New Issue
Block a user