Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.1 kB
1
Indexable
Never
#part 1

cleaned_inputs = [s.split('|') for s in [i.split(':')[1] for i in inputs]]

score_total = 0
for numbers in cleaned_inputs:
    winning_nos = numbers[0].split()
    guessed_nos = numbers[1].split()
    number_correct = len([i for i in guessed_nos if i in winning_nos])
    if number_correct == 0:
        continue
    else:
        score_total += 2**(number_correct-1)

score_total

#part 2

no_of_cards = (len(cleaned_inputs))
no_correct_by_card = []

card_multipliers = [1 for i in range(no_of_cards)]

for card_no, numbers in enumerate(cleaned_inputs):
    winning_nos = numbers[0].split()
    guessed_nos = numbers[1].split()
    multiplier = card_multipliers[card_no]
    number_correct = len([i for i in guessed_nos if i in winning_nos])
    no_correct_by_card.append(number_correct)
    if number_correct == 0:
        continue
    else:
        card_multipliers[card_no+1:card_no+number_correct+1] = [i + (1*multiplier) for i in card_multipliers[card_no+1:card_no+number_correct+1]]

sum(card_multipliers)
Leave a Comment