From a578c4df9760b8cd569beea845ee7c2ca0cdc42c Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Sat, 3 Dec 2022 09:22:10 +0200 Subject: [PATCH] day 3 second answer and clean up --- 03/c.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/03/c.py b/03/c.py index 7eb8465..3b0cd65 100644 --- a/03/c.py +++ b/03/c.py @@ -6,19 +6,28 @@ tot = 0 tot2 = 0 priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - - commons = '' rucksacks = f.read().splitlines() +rucksacks2 = [] for data in rucksacks: left = data[:len(data)//2] right = data[len(data)//2:] - print(str(left) + " " + str(right)) common = ''.join(set(left).intersection(right)) tot = tot + priorities.rfind(common)+1 -print(tot) +print("First answer: " + str(tot)) + +start = 0 +end = len(rucksacks) +step = 3 +for i in range(start, end, step): + + three = rucksacks[i:i+step] + common = set(three[0]) & set(three[1]) & set(three[2]) + tot2 = tot2 + priorities.rfind(''.join(common))+1 + +print("Second answer: " + str(tot2))