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.

trying to learn python

vals=0
with open("03RucksackReorganization.txt","r") as lines:
    for line in lines:
        dropN=line.rstrip("\n")
        first, second=dropN[:len(dropN)//2], dropN[len(dropN)//2:]
        letters=set(first)
        for ch in second:
            if ch in letters:
                vals+=(ord(ch.lower())-ord('a')+1 + (0 if ch.lower() else 26))
                break
print(vals) 

and part two:

vals=0
with open("03RucksackReorganization.txt","r") as lines:
    index=0
    seen=set()
    for line in lines:
        sansN=line.rstrip("\n")
        if(index==0):
            seen=set(sansN)
        else:
            seen=seen.intersection(set(sansN))
        if(index==2):
            ch=seen.pop()
            vals+=(ord(ch.lower())-ord('a')+1 + (0 if ch.islower() else 26))
            seen.clear()
        index=(index+1)%3
print(vals)
Jump in the discussion.

No email address required.

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