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.

Basically the same as Geese's grugbrained tbh. … ALSO: Once again wondering who 986674 and 2339424 are :marseypregunta:

def _priority(self, itm):
    if ord(itm) > ord('Z'):
        return ord(itm) - ord('a') + 1
    return ord(itm) - ord('A') + 27

def run_a(self, data):
    acc = 0
    for l in data:
        sz = len(l) // 2
        ca, cb = l[0:sz], l[sz:len(l)]
        for x in ca:
            if x in cb:
                acc += self._priority(x)
                break
    return acc

def run_b(self, data):
    acc = 0
    for i in range(len(data) // 3):
        for x in data[3*i]:
            if x in data[3*i + 1] and x in data[3*i + 2]:
                acc += self._priority(x)
                break
    return acc
Jump in the discussion.

No email address required.

I keep setting ORD values using absolute numbers because I'm r-slurred and forget I can feed the char itself in. I'm hoping seeing you do it properly will shock some sense into me.

Jump in the discussion.

No email address required.

i am 2339424

Jump in the discussion.

No email address required.

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