annotate day6.txt @ 21:46fb65f2cb94

Add Day 14 part 1 implementation If you look at columns and see "how far can this go" then the weight is just the sum of the partial triangle numbers of highest_weight to highest_weight minus number of rocks that can roll up to there. Part 2 seems to involve actually moving the rocks, though!
author IBBoard <dev@ibboard.co.uk>
date Sat, 16 Dec 2023 10:29:36 +0000
parents 1e16a25a9553
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 --- Day 6: Wait For It ---
9d89489bc939 Day 6 part 1 - calculate times above range
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: 7
diff changeset
3 There is a race for toy boats with a button on top. Holding down the button charges the boat, and releasing the button allows the boat to move. Boats move faster if their button was held longer, but time spent holding the button counts against the total race time. You can only hold the button at the start of the race, and boats don't move until the button is released. You want to beat the record distance for a given race duration.
6
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 For example:
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 Time: 7 15 30
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 Distance: 9 40 200
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 This document describes three races:
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 The first race lasts 7 milliseconds. The record distance in this race is 9 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 The second race lasts 15 milliseconds. The record distance in this race is 40 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 The third race lasts 30 milliseconds. The record distance in this race is 200 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 Your toy boat has a starting speed of zero millimeters per millisecond. For each whole millisecond you spend at the beginning of the race holding down the button, the boat's speed increases by one millimeter per millisecond.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 So, because the first race lasts 7 milliseconds, you only have a few options:
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 Don't hold the button at all (that is, hold it for 0 milliseconds) at the start of the race. The boat won't move; it will have traveled 0 millimeters by the end of the race.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 Hold the button for 1 millisecond at the start of the race. Then, the boat will travel at a speed of 1 millimeter per millisecond for 6 milliseconds, reaching a total distance traveled of 6 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 Hold the button for 2 milliseconds, giving the boat a speed of 2 millimeters per millisecond. It will then get 5 milliseconds to move, reaching a total distance of 10 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 Hold the button for 3 milliseconds. After its remaining 4 milliseconds of travel time, the boat will have gone 12 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 Hold the button for 4 milliseconds. After its remaining 3 milliseconds of travel time, the boat will have gone 12 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 Hold the button for 5 milliseconds, causing the boat to travel a total of 10 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 Hold the button for 6 milliseconds, causing the boat to travel a total of 6 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 Hold the button for 7 milliseconds. That's the entire duration of the race. You never let go of the button. The boat can't move until you let go of the button. Please make sure you let go of the button so the boat gets to move. 0 millimeters.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 Since the current record for this race is 9 millimeters, there are actually 4 different ways you could win: you could hold the button for 2, 3, 4, or 5 milliseconds at the start of the race.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 In the second race, you could hold the button for at least 4 milliseconds and at most 11 milliseconds and beat the record, a total of 8 different ways to win.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 In the third race, you could hold the button for at least 11 milliseconds and no more than 19 milliseconds and still beat the record, a total of 9 ways you could win.
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 To see how much margin of error you have, determine the number of ways you can beat the record in each race; in this example, if you multiply these values together, you get 288 (4 * 8 * 9).
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
9d89489bc939 Day 6 part 1 - calculate times above range
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 Determine the number of ways you could beat the record in each race. What do you get if you multiply these numbers together?
7
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
38
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
39 --- Part Two ---
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
40
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 7
diff changeset
41 The race times and record distances you got earlier are really only one race - ignore the spaces between the numbers on each line.
7
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
42
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
43 So, the example from before:
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
44
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
45 Time: 7 15 30
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
46 Distance: 9 40 200
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
47
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
48 ...now instead means this:
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
49
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
50 Time: 71530
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
51 Distance: 940200
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
52
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
53 Now, you have to figure out how many ways there are to win this single race. In this example, the race lasts for 71530 milliseconds and the record distance you need to beat is 940200 millimeters. You could hold the button anywhere from 14 to 71516 milliseconds and beat the record, a total of 71503 ways!
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
54
6e0615e54e71 Restructure input parsing for day6b
IBBoard <dev@ibboard.co.uk>
parents: 6
diff changeset
55 How many ways can you beat the record in this one much longer race?