From 5b57327db2d7456ef803e0bab6a699a98707d82b Mon Sep 17 00:00:00 2001 From: aaron Date: Mon, 4 Dec 2023 22:45:05 +0100 Subject: [PATCH] cleanup --- 4/scratchcards.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/4/scratchcards.py b/4/scratchcards.py index be1e1ee..af6abd8 100644 --- a/4/scratchcards.py +++ b/4/scratchcards.py @@ -51,29 +51,23 @@ def new_rules(input_data: list) -> list: Calculate the score for the updated rule set. - If your card has n matches, get the next n cards - repeat until there are no more matches + - return the total number of cards you've accumulated """ data = input_data.split("\n") - score, win, total = 0, 0, 0 - cardcounts = [] - for i in range(len(data)): - cardcounts.append(1) - for x, row in enumerate(data): + cards = [1 for i in range(len(data))] + + win = 0 + for i, row in enumerate(data): wins = row.split("|")[0].split(":")[1].split() nums = row.split("|")[1].split() for num in nums: if num in wins: win += 1 - if score == 0: - score = 1 - else: - score *= 2 - for i in range(win): - cardcounts[x + i + 1] += cardcounts[x] - total += score - score, win = 0, 0 - - return cardcounts + for j in range(win): + cards[i + j + 1] += cards[i] + win = 0 + return cards if __name__ == "__main__":