advent of code day 3: i might be r-slurred edition

idk how to do multi line spoilers lol



letters = ['','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

total_score = 0

team = []

for line in open("input.txt"):
    team.append(line.strip())

for i in range(2, len(team), 3):
    for letter in team[i]:
        if letter in team[i-2] and letter in team[i-1]:
            total_score += letters.index(letter)
            break

print(total_score)

some real caveman shit but it works

80
Jump in the discussion.

No email address required.

import string
from itertools import islice

priority = {c:i for i, c in enumerate(string.ascii_letters,1)}

# part 1
with open('./input.txt') as infile:
    score = 0
    for line in map(str.strip, infile):
        n = len(line) // 2
        a, b = set(line[:n]), set(line[n:])
        item = a.intersection(b)
        score += priority[item.pop()]
print(score)

# part 2
with open('./input.txt') as infile:
    score = 0
    lines = map(str.strip, infile)
    while g := list(islice(lines, 3)):
        a, b, c = map(set, g)
        item = a.intersection(b,c)
        score += priority[item.pop()]
print(score)
Jump in the discussion.

No email address required.

that's a pretty cool way to iterate over chunks, will steal

Jump in the discussion.

No email address required.



Now playing: Bayou Boogie (DKC2).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.