annotate day4.txt @ 26:eb6c3a7d2f72

Constrained and more optimised route finding * Track routes so we can see if we have gone straight for too long * Track multiple routes so we can use a non-optimal route to X if it makes another route to Y through X possible (e.g. optimal route takes three consecutive steps to X, but then has to turn, whereas a longer straight earlier and two consecutive steps to X gives a much better next hop to Y) * We have a start point, so only include the nodes from the search front in "unvisited" to avoid looking at lots of irrelevant nodes
author IBBoard <dev@ibboard.co.uk>
date Sun, 17 Dec 2023 20:13:03 +0000
parents 1e16a25a9553
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 --- Day 4: Scratchcards ---
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
3 Each scratchcard has two lists of numbers separated by a vertical bar (|): a list of winning numbers and then a list of numbers you have. You organize the information into a table (your puzzle input).
3
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
5 You have to figure out which of the numbers you have appear in the list of winning numbers. The first match makes the card worth one point and each match after the first doubles the point value of that card.
3
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 For example:
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 In the above example, card 1 has five winning numbers (41, 48, 83, 86, and 17) and eight numbers you have (83, 86, 6, 31, 17, 9, 48, and 53). Of the numbers you have, four of them (48, 83, 17, and 86) are winning numbers! That means card 1 is worth 8 points (1 for the first match, then doubled three times for each of the three matches after the first).
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 Card 2 has two winning numbers (32 and 61), so it is worth 2 points.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 Card 3 has two winning numbers (1 and 21), so it is worth 2 points.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 Card 4 has one winning number (84), so it is worth 1 point.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 Card 5 has no winning numbers, so it is worth no points.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 Card 6 has no winning numbers, so it is worth no points.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
24 So, in this example, the scratchcards are worth 13 points.
3
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
26 How many points is the puzzle input worth in total?
3
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 --- Part Two ---
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
30 Actually, there's no such thing as "points". Instead, scratchcards only cause you to win more scratchcards equal to the number of winning numbers you have.
3
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 Specifically, you win copies of the scratchcards below the winning card equal to the number of matches. So, if card 10 were to have 5 matching numbers, you would win one copy each of cards 11, 12, 13, 14, and 15.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 Copies of scratchcards are scored like normal scratchcards and have the same card number as the card they copied. So, if you win a copy of card 10 and it has 5 matching numbers, it would then win a copy of the same cards that the original card 10 won: cards 11, 12, 13, 14, and 15. This process repeats until none of the copies cause you to win any more cards. (Cards will never make you copy a card past the end of the table.)
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 This time, the above example goes differently:
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 Card 1 has four matching numbers, so you win one copy each of the next four cards: cards 2, 3, 4, and 5.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 Your original card 2 has two matching numbers, so you win one copy each of cards 3 and 4.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 Your copy of card 2 also wins one copy each of cards 3 and 4.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 Your four instances of card 3 (one original and three copies) have two matching numbers, so you win four copies each of cards 4 and 5.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 Your eight instances of card 4 (one original and seven copies) have one matching number, so you win eight copies of card 5.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 Your fourteen instances of card 5 (one original and thirteen copies) have no matching numbers and win no more cards.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 Your one instance of card 6 (one original) has no matching numbers and wins no more cards.
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 Once all of the originals and copies have been processed, you end up with 1 instance of card 1, 2 instances of card 2, 4 instances of card 3, 8 instances of card 4, 14 instances of card 5, and 1 instance of card 6. In total, this example pile of scratchcards causes you to ultimately have 30 scratchcards!
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54
9da7a71b313d Implement scratchcard counting for Day 4
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 Process all of the original and copied scratchcards until no more scratchcards are won. Including the original set of scratchcards, how many total scratchcards do you end up with?