From 014b656137a206845c0fda3df1a0132d3861878f Mon Sep 17 00:00:00 2001 From: kleph Date: Sun, 1 Dec 2024 13:49:36 +0100 Subject: [PATCH] 2024 - Day 1 part 2 --- 2024/1/1_2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 2024/1/1_2.py diff --git a/2024/1/1_2.py b/2024/1/1_2.py new file mode 100644 index 0000000..e286261 --- /dev/null +++ b/2024/1/1_2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# 2024 - Advent Of Code 1 - part 2 + +# file = 'input_example.txt' +file = 'input.txt' + +firsts = [] +seconds = {} +accum = 0 +with open(file, encoding="utf-8") as f: + for line in f.readlines(): + a, b, c, d = line.strip().split(' ') + firsts.append(int(a)) + if int(d) in seconds: + seconds[int(d)] += 1 + else: + seconds[int(d)] = 1 + +for num in firsts: + if num in seconds: + accum += num * seconds[num] + +print(f"sum: {accum}")