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.

Late submission, but I was recovering from a hangover from a party last night so meh.

with open('day3_input.txt', 'r') as inp:
    foo = inp.read().split('\n')

def check(n):
    for a in n[:len(n)//2]:
        if a in n[len(n)//2:]:
            return a

def convert(c):
    val = ord(c)
    if val < 97:
        return val-38
    return val-96

total = 0
for f in foo:
    total += convert(check(f))
print(total)

def check2(a, b, c):
    for x in a:
        if x in b and x in c:
            return x

total = 0
for g in range(0, len(foo), 3):
    total += convert(check2(foo[g], foo[g+1], foo[g+2]))
print(total)
Jump in the discussion.

No email address required.

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