Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed-dash committed Dec 28, 2023
1 parent ea38467 commit ee95345
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,8 @@
" - I split the `winning` and `actual` numbers at the space, using `split()`. This gives me a list of string values. Then I convert the string values to `int` using `map()`, and finally convert each `list` to a `set`.\n",
" - Now I can create an instance of `ScoreCard` from the `id` and the two sets.\n",
"\n",
"- I've added a `matches()` method to my `ScatchCard`. This method uses the _intersects_ operator (`&`) to determine which numbers are present in both the `winning` set and the `actual` set. See more on this [here](https://aoc.just2good.co.uk/python/sets).\n",
"\n",
"- Finally, just add up all the scores from each card using `sum` and a [list comprehension](https://aoc.just2good.co.uk/python/comprehensions)."
]
},
Expand Down Expand Up @@ -1789,7 +1791,7 @@
"\n",
"Now we're told that there's no such thing as a _score_. Instead scratchcards only cause you to win more scratchcards equal to the number of winning numbers you have. You win copies of the scratchcards below the winning card equal to the number of matches.\n",
"\n",
"**how many total scratchcards do you end up with?**\n",
"**How many total scratchcards do you end up with?**\n",
"\n",
"**My solution**\n",
"\n",
Expand All @@ -1799,7 +1801,7 @@
"\n",
"- Create a `dict` that stores the number of cards for each card ID.\n",
"- Loop through all the cards we have to initialise the dict. There will be one of each.\n",
"- Then, loop through the cards again, in order. For each card:\n",
"- Then, loop through the cards again, in order. For each card:\n",
" - Get the number of matches.\n",
" - Use this number of matches to determine the successive cards that need to be duplicated.\n",
" - Increment the count of each of those successive cards, by the count of the card we're currently on. (Because it might not be 1.)\n",
Expand All @@ -1816,9 +1818,7 @@
"outputs": [],
"source": [
"def solve_part2(cards: list[ScratchCard]):\n",
" card_counts = {}\n",
" for card in cards: # initialise our card counts \n",
" card_counts[card.id] = 1\n",
" card_counts = { card.id: 1 for card in cards } # initialise count to 1 for each original card\n",
" \n",
" for card in cards:\n",
" count_this_card = card_counts[card.id]\n",
Expand Down

0 comments on commit ee95345

Please sign in to comment.