description.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. --- Day 20: Race Condition ---
  2. The Historians are quite pixelated again. This time, a massive, black building looms over you - you're right outside the CPU!
  3. While The Historians get to work, a nearby program sees that you're idle and challenges you to a race. Apparently, you've arrived just in time for the frequently-held race condition festival!
  4. The race takes place on a particularly long and twisting code path; programs compete to see who can finish in the fewest picoseconds. The winner even gets their very own mutex!
  5. They hand you a map of the racetrack (your puzzle input). For example:
  6. ###############
  7. #...#...#.....#
  8. #.#.#.#.#.###.#
  9. #S#...#.#.#...#
  10. #######.#.#.###
  11. #######.#.#...#
  12. #######.#.###.#
  13. ###..E#...#...#
  14. ###.#######.###
  15. #...###...#...#
  16. #.#####.#.###.#
  17. #.#...#.#.#...#
  18. #.#.#.#.#.#.###
  19. #...#...#...###
  20. ###############
  21. The map consists of track (.) - including the start (S) and end (E) positions (both of which also count as track) - and walls (#).
  22. When a program runs through the racetrack, it starts at the start position. Then, it is allowed to move up, down, left, or right; each such move takes 1 picosecond. The goal is to reach the end position as quickly as possible. In this example racetrack, the fastest time is 84 picoseconds.
  23. Because there is only a single path from the start to the end and the programs all go the same speed, the races used to be pretty boring. To make things more interesting, they introduced a new rule to the races: programs are allowed to cheat.
  24. The rules for cheating are very strict. Exactly once during a race, a program may disable collision for up to 2 picoseconds. This allows the program to pass through walls as if they were regular track. At the end of the cheat, the program must be back on normal track again; otherwise, it will receive a segmentation fault and get disqualified.
  25. So, a program could complete the course in 72 picoseconds (saving 12 picoseconds) by cheating for the two moves marked 1 and 2:
  26. ###############
  27. #...#...12....#
  28. #.#.#.#.#.###.#
  29. #S#...#.#.#...#
  30. #######.#.#.###
  31. #######.#.#...#
  32. #######.#.###.#
  33. ###..E#...#...#
  34. ###.#######.###
  35. #...###...#...#
  36. #.#####.#.###.#
  37. #.#...#.#.#...#
  38. #.#.#.#.#.#.###
  39. #...#...#...###
  40. ###############
  41. Or, a program could complete the course in 64 picoseconds (saving 20 picoseconds) by cheating for the two moves marked 1 and 2:
  42. ###############
  43. #...#...#.....#
  44. #.#.#.#.#.###.#
  45. #S#...#.#.#...#
  46. #######.#.#.###
  47. #######.#.#...#
  48. #######.#.###.#
  49. ###..E#...12..#
  50. ###.#######.###
  51. #...###...#...#
  52. #.#####.#.###.#
  53. #.#...#.#.#...#
  54. #.#.#.#.#.#.###
  55. #...#...#...###
  56. ###############
  57. This cheat saves 38 picoseconds:
  58. ###############
  59. #...#...#.....#
  60. #.#.#.#.#.###.#
  61. #S#...#.#.#...#
  62. #######.#.#.###
  63. #######.#.#...#
  64. #######.#.###.#
  65. ###..E#...#...#
  66. ###.####1##.###
  67. #...###.2.#...#
  68. #.#####.#.###.#
  69. #.#...#.#.#...#
  70. #.#.#.#.#.#.###
  71. #...#...#...###
  72. ###############
  73. This cheat saves 64 picoseconds and takes the program directly to the end:
  74. ###############
  75. #...#...#.....#
  76. #.#.#.#.#.###.#
  77. #S#...#.#.#...#
  78. #######.#.#.###
  79. #######.#.#...#
  80. #######.#.###.#
  81. ###..21...#...#
  82. ###.#######.###
  83. #...###...#...#
  84. #.#####.#.###.#
  85. #.#...#.#.#...#
  86. #.#.#.#.#.#.###
  87. #...#...#...###
  88. ###############
  89. Each cheat has a distinct start position (the position where the cheat is activated, just before the first move that is allowed to go through walls) and end position; cheats are uniquely identified by their start position and end position.
  90. In this example, the total number of cheats (grouped by the amount of time they save) are as follows:
  91. There are 14 cheats that save 2 picoseconds.
  92. There are 14 cheats that save 4 picoseconds.
  93. There are 2 cheats that save 6 picoseconds.
  94. There are 4 cheats that save 8 picoseconds.
  95. There are 2 cheats that save 10 picoseconds.
  96. There are 3 cheats that save 12 picoseconds.
  97. There is one cheat that saves 20 picoseconds.
  98. There is one cheat that saves 36 picoseconds.
  99. There is one cheat that saves 38 picoseconds.
  100. There is one cheat that saves 40 picoseconds.
  101. There is one cheat that saves 64 picoseconds.
  102. You aren't sure what the conditions of the racetrack will be like, so to give yourself as many options as possible, you'll need a list of the best cheats. How many cheats would save you at least 100 picoseconds?
  103. The first half of this puzzle is complete! It provides one gold star: *
  104. --- Part Two ---
  105. The programs seem perplexed by your list of cheats. Apparently, the two-picosecond cheating rule was deprecated several milliseconds ago! The latest version of the cheating rule permits a single cheat that instead lasts at most 20 picoseconds.
  106. Now, in addition to all the cheats that were possible in just two picoseconds, many more cheats are possible. This six-picosecond cheat saves 76 picoseconds:
  107. ###############
  108. #...#...#.....#
  109. #.#.#.#.#.###.#
  110. #S#...#.#.#...#
  111. #1#####.#.#.###
  112. #2#####.#.#...#
  113. #3#####.#.###.#
  114. #456.E#...#...#
  115. ###.#######.###
  116. #...###...#...#
  117. #.#####.#.###.#
  118. #.#...#.#.#...#
  119. #.#.#.#.#.#.###
  120. #...#...#...###
  121. ###############
  122. Because this cheat has the same start and end positions as the one above, it's the same cheat, even though the path taken during the cheat is different:
  123. ###############
  124. #...#...#.....#
  125. #.#.#.#.#.###.#
  126. #S12..#.#.#...#
  127. ###3###.#.#.###
  128. ###4###.#.#...#
  129. ###5###.#.###.#
  130. ###6.E#...#...#
  131. ###.#######.###
  132. #...###...#...#
  133. #.#####.#.###.#
  134. #.#...#.#.#...#
  135. #.#.#.#.#.#.###
  136. #...#...#...###
  137. ###############
  138. Cheats don't need to use all 20 picoseconds; cheats can last any amount of time up to and including 20 picoseconds (but can still only end when the program is on normal track). Any cheat time not used is lost; it can't be saved for another cheat later.
  139. You'll still need a list of the best cheats, but now there are even more to choose between. Here are the quantities of cheats in this example that save 50 picoseconds or more:
  140. There are 32 cheats that save 50 picoseconds.
  141. There are 31 cheats that save 52 picoseconds.
  142. There are 29 cheats that save 54 picoseconds.
  143. There are 39 cheats that save 56 picoseconds.
  144. There are 25 cheats that save 58 picoseconds.
  145. There are 23 cheats that save 60 picoseconds.
  146. There are 20 cheats that save 62 picoseconds.
  147. There are 19 cheats that save 64 picoseconds.
  148. There are 12 cheats that save 66 picoseconds.
  149. There are 14 cheats that save 68 picoseconds.
  150. There are 12 cheats that save 70 picoseconds.
  151. There are 22 cheats that save 72 picoseconds.
  152. There are 4 cheats that save 74 picoseconds.
  153. There are 3 cheats that save 76 picoseconds.
  154. Find the best cheats using the updated cheating rules. How many cheats would save you at least 100 picoseconds?