From 91f1535c7394e36c3f0c0b56295436c26751c024 Mon Sep 17 00:00:00 2001 From: Starnakin Date: Sun, 1 Dec 2024 21:04:06 +0100 Subject: [PATCH] add: 2024/day01/part2 --- 2024/day01/part2.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 2024/day01/part2.py diff --git a/2024/day01/part2.py b/2024/day01/part2.py new file mode 100644 index 0000000..b3075a4 --- /dev/null +++ b/2024/day01/part2.py @@ -0,0 +1,18 @@ +text: str + +with open("test.txt") as f: + text = f.read() + +lines: list[str] = text.splitlines() +data: list[list[str]] = [line.split(" ") for line in lines] + +right_data: list[str] = [tmp[1] for tmp in data] +left_data: list[str] = [tmp[0] for tmp in data] + +right: list[int] = list(map(int, right_data)) +left: list[int] = list(map(int, left_data)) + +right.sort() +left.sort() + +print(sum(map(abs, [x * right.count(x) for x in left]))) \ No newline at end of file