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.

Euro Times.... Cant compete but do it any way:

with open('input03.txt') as file:
    lines = [line.rstrip() for line in file]

def get_priority(item):
    if item >= 97:
        item -= 96
    else:
        item -= 38
    return item

#a
count = 0
for line in lines:
    half = int(len(line)/2)
    first = line[:half]
    second = line[half:]
    intersection = set(first).intersection(set(second))
    item = ord(intersection.pop()) # looked up. Only one item per intersect
    priority = get_priority(item)
    count += priority
print(count)

#b
index = 0
count = 0
while index < len(lines):
    intersection = set(lines[index]).intersection(set(lines[index+1])).intersection(set(lines[index+2]))
    item = ord(intersection.pop())
    priority = get_priority(item)
    count += priority
    index += 3
print(count)

@AverageMistletoeEnjoyer intersection() gang gang

Jump in the discussion.

No email address required.

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