diff options
author | boredpasta <boredpasta@tutanota.com> | 2025-01-13 07:00:52 +0200 |
---|---|---|
committer | boredpasta <boredpasta@tutanota.com> | 2025-01-13 07:22:23 +0200 |
commit | f85949f85266768ec1bd5e3d150e4ac71feabcf1 (patch) | |
tree | a6c81c5ec164d209bf0e664d6a6a22ddd42cd63f /2022/03/rucksack.py | |
parent | af9283db3825dbfede0a4127a004f0b077fe6f7c (diff) |
Diffstat (limited to '2022/03/rucksack.py')
-rw-r--r-- | 2022/03/rucksack.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/2022/03/rucksack.py b/2022/03/rucksack.py new file mode 100644 index 0000000..30efa92 --- /dev/null +++ b/2022/03/rucksack.py @@ -0,0 +1,30 @@ +def priority(c): + if (ord(c) >= ord("a")): + return ord(c) - ord("a") + 1 + else: + return ord(c) - ord("A") + 27 +def same(x, y): + a = set() + for x1 in x: + if x1 in y: + a.add(x1) + return list(a) +def inlists(x, y): + isin = [] + for x1 in x: + if all([x1 in y1 for y1 in y]): + isin.append(x1) + if len(isin) > 0: + return isin[0] + return None + +with open("input") as f: + compartments = [line.strip() for line in f.readlines()] +points = 0 +for i in range(0, len(compartments), 3): + group = compartments[i:i+3] + if len(group) == 3: + c = inlists(group[0], group[1:]) + if c is not None: + points += priority(c) +print(points) |