diff options
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) |