From 89bd320991451231b8b659df8509397cd2b4cdca Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Sat, 3 Dec 2022 09:02:54 +0200 Subject: [PATCH] day 3 first answer --- 03/c.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 03/c.py diff --git a/03/c.py b/03/c.py new file mode 100644 index 0000000..7eb8465 --- /dev/null +++ b/03/c.py @@ -0,0 +1,24 @@ +import os + +f = open(os.path.dirname(__file__)+"/input.txt", "r") + +tot = 0 +tot2 = 0 + +priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + + +commons = '' + +rucksacks = f.read().splitlines() + +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)