description.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. --- Day 9: Rope Bridge ---
  2. This rope bridge creaks as you walk along it. You aren't sure how old it is, or whether it can even support your weight.
  3. It seems to support the Elves just fine, though. The bridge spans a gorge which was carved out by the massive river far below you.
  4. You step carefully; as you do, the ropes stretch and twist. You decide to distract yourself by modeling rope physics; maybe you can even figure out where not to step.
  5. Consider a rope with a knot at each end; these knots mark the head and the tail of the rope. If the head moves far enough away from the tail, the tail is pulled toward the head.
  6. Due to nebulous reasoning involving Planck lengths, you should be able to model the positions of the knots on a two-dimensional grid. Then, by following a hypothetical series of motions (your puzzle input) for the head, you can determine how the tail will move.
  7. Due to the aforementioned Planck lengths, the rope must be quite short; in fact, the head (H) and tail (T) must always be touching (diagonally adjacent and even overlapping both count as touching):
  8. ....
  9. .TH.
  10. ....
  11. ....
  12. .H..
  13. ..T.
  14. ....
  15. ...
  16. .H. (H covers T)
  17. ...
  18. If the head is ever two steps directly up, down, left, or right from the tail, the tail must also move one step in that direction so it remains close enough:
  19. ..... ..... .....
  20. .TH.. -> .T.H. -> ..TH.
  21. ..... ..... .....
  22. ... ... ...
  23. .T. .T. ...
  24. .H. -> ... -> .T.
  25. ... .H. .H.
  26. ... ... ...
  27. Otherwise, if the head and tail aren't touching and aren't in the same row or column, the tail always moves one step diagonally to keep up:
  28. ..... ..... .....
  29. ..... ..H.. ..H..
  30. ..H.. -> ..... -> ..T..
  31. .T... .T... .....
  32. ..... ..... .....
  33. ..... ..... .....
  34. ..... ..... .....
  35. ..H.. -> ...H. -> ..TH.
  36. .T... .T... .....
  37. ..... ..... .....
  38. You just need to work out where the tail goes as the head follows a series of motions. Assume the head and the tail both start at the same position, overlapping.
  39. For example:
  40. R 4
  41. U 4
  42. L 3
  43. D 1
  44. R 4
  45. D 1
  46. L 5
  47. R 2
  48. This series of motions moves the head right four steps, then up four steps, then left three steps, then down one step, and so on. After each step, you'll need to update the position of the tail if the step means the head is no longer adjacent to the tail. Visually, these motions occur as follows (s marks the starting position as a reference point):
  49. == Initial State ==
  50. ......
  51. ......
  52. ......
  53. ......
  54. H..... (H covers T, s)
  55. == R 4 ==
  56. ......
  57. ......
  58. ......
  59. ......
  60. TH.... (T covers s)
  61. ......
  62. ......
  63. ......
  64. ......
  65. sTH...
  66. ......
  67. ......
  68. ......
  69. ......
  70. s.TH..
  71. ......
  72. ......
  73. ......
  74. ......
  75. s..TH.
  76. == U 4 ==
  77. ......
  78. ......
  79. ......
  80. ....H.
  81. s..T..
  82. ......
  83. ......
  84. ....H.
  85. ....T.
  86. s.....
  87. ......
  88. ....H.
  89. ....T.
  90. ......
  91. s.....
  92. ....H.
  93. ....T.
  94. ......
  95. ......
  96. s.....
  97. == L 3 ==
  98. ...H..
  99. ....T.
  100. ......
  101. ......
  102. s.....
  103. ..HT..
  104. ......
  105. ......
  106. ......
  107. s.....
  108. .HT...
  109. ......
  110. ......
  111. ......
  112. s.....
  113. == D 1 ==
  114. ..T...
  115. .H....
  116. ......
  117. ......
  118. s.....
  119. == R 4 ==
  120. ..T...
  121. ..H...
  122. ......
  123. ......
  124. s.....
  125. ..T...
  126. ...H..
  127. ......
  128. ......
  129. s.....
  130. ......
  131. ...TH.
  132. ......
  133. ......
  134. s.....
  135. ......
  136. ....TH
  137. ......
  138. ......
  139. s.....
  140. == D 1 ==
  141. ......
  142. ....T.
  143. .....H
  144. ......
  145. s.....
  146. == L 5 ==
  147. ......
  148. ....T.
  149. ....H.
  150. ......
  151. s.....
  152. ......
  153. ....T.
  154. ...H..
  155. ......
  156. s.....
  157. ......
  158. ......
  159. ..HT..
  160. ......
  161. s.....
  162. ......
  163. ......
  164. .HT...
  165. ......
  166. s.....
  167. ......
  168. ......
  169. HT....
  170. ......
  171. s.....
  172. == R 2 ==
  173. ......
  174. ......
  175. .H.... (H covers T)
  176. ......
  177. s.....
  178. ......
  179. ......
  180. .TH...
  181. ......
  182. s.....
  183. After simulating the rope, you can count up all of the positions the tail visited at least once. In this diagram, s again marks the starting position (which the tail also visited) and # marks other positions the tail visited:
  184. ..##..
  185. ...##.
  186. .####.
  187. ....#.
  188. s###..
  189. So, there are 13 positions the tail visited at least once.
  190. Simulate your complete hypothetical series of motions. How many positions does the tail of the rope visit at least once?
  191. Your puzzle answer was 6642.
  192. The first half of this puzzle is complete! It provides one gold star: *
  193. --- Part Two ---
  194. A rope snaps! Suddenly, the river is getting a lot closer than you remember. The bridge is still there, but some of the ropes that broke are now whipping toward you as you fall through the air!
  195. The ropes are moving too quickly to grab; you only have a few seconds to choose how to arch your body to avoid being hit. Fortunately, your simulation can be extended to support longer ropes.
  196. Rather than two knots, you now must simulate a rope consisting of ten knots. One knot is still the head of the rope and moves according to the series of motions. Each knot further down the rope follows the knot in front of it using the same rules as before.
  197. Using the same series of motions as the above example, but with the knots marked H, 1, 2, ..., 9, the motions now occur as follows:
  198. == Initial State ==
  199. ......
  200. ......
  201. ......
  202. ......
  203. H..... (H covers 1, 2, 3, 4, 5, 6, 7, 8, 9, s)
  204. == R 4 ==
  205. ......
  206. ......
  207. ......
  208. ......
  209. 1H.... (1 covers 2, 3, 4, 5, 6, 7, 8, 9, s)
  210. ......
  211. ......
  212. ......
  213. ......
  214. 21H... (2 covers 3, 4, 5, 6, 7, 8, 9, s)
  215. ......
  216. ......
  217. ......
  218. ......
  219. 321H.. (3 covers 4, 5, 6, 7, 8, 9, s)
  220. ......
  221. ......
  222. ......
  223. ......
  224. 4321H. (4 covers 5, 6, 7, 8, 9, s)
  225. == U 4 ==
  226. ......
  227. ......
  228. ......
  229. ....H.
  230. 4321.. (4 covers 5, 6, 7, 8, 9, s)
  231. ......
  232. ......
  233. ....H.
  234. .4321.
  235. 5..... (5 covers 6, 7, 8, 9, s)
  236. ......
  237. ....H.
  238. ....1.
  239. .432..
  240. 5..... (5 covers 6, 7, 8, 9, s)
  241. ....H.
  242. ....1.
  243. ..432.
  244. .5....
  245. 6..... (6 covers 7, 8, 9, s)
  246. == L 3 ==
  247. ...H..
  248. ....1.
  249. ..432.
  250. .5....
  251. 6..... (6 covers 7, 8, 9, s)
  252. ..H1..
  253. ...2..
  254. ..43..
  255. .5....
  256. 6..... (6 covers 7, 8, 9, s)
  257. .H1...
  258. ...2..
  259. ..43..
  260. .5....
  261. 6..... (6 covers 7, 8, 9, s)
  262. == D 1 ==
  263. ..1...
  264. .H.2..
  265. ..43..
  266. .5....
  267. 6..... (6 covers 7, 8, 9, s)
  268. == R 4 ==
  269. ..1...
  270. ..H2..
  271. ..43..
  272. .5....
  273. 6..... (6 covers 7, 8, 9, s)
  274. ..1...
  275. ...H.. (H covers 2)
  276. ..43..
  277. .5....
  278. 6..... (6 covers 7, 8, 9, s)
  279. ......
  280. ...1H. (1 covers 2)
  281. ..43..
  282. .5....
  283. 6..... (6 covers 7, 8, 9, s)
  284. ......
  285. ...21H
  286. ..43..
  287. .5....
  288. 6..... (6 covers 7, 8, 9, s)
  289. == D 1 ==
  290. ......
  291. ...21.
  292. ..43.H
  293. .5....
  294. 6..... (6 covers 7, 8, 9, s)
  295. == L 5 ==
  296. ......
  297. ...21.
  298. ..43H.
  299. .5....
  300. 6..... (6 covers 7, 8, 9, s)
  301. ......
  302. ...21.
  303. ..4H.. (H covers 3)
  304. .5....
  305. 6..... (6 covers 7, 8, 9, s)
  306. ......
  307. ...2..
  308. ..H1.. (H covers 4; 1 covers 3)
  309. .5....
  310. 6..... (6 covers 7, 8, 9, s)
  311. ......
  312. ...2..
  313. .H13.. (1 covers 4)
  314. .5....
  315. 6..... (6 covers 7, 8, 9, s)
  316. ......
  317. ......
  318. H123.. (2 covers 4)
  319. .5....
  320. 6..... (6 covers 7, 8, 9, s)
  321. == R 2 ==
  322. ......
  323. ......
  324. .H23.. (H covers 1; 2 covers 4)
  325. .5....
  326. 6..... (6 covers 7, 8, 9, s)
  327. ......
  328. ......
  329. .1H3.. (H covers 2, 4)
  330. .5....
  331. 6..... (6 covers 7, 8, 9, s)
  332. Now, you need to keep track of the positions the new tail, 9, visits. In this example, the tail never moves, and so it only visits 1 position. However, be careful: more types of motion are possible than before, so you might want to visually compare your simulated rope to the one above.
  333. Here's a larger example:
  334. R 5
  335. U 8
  336. L 8
  337. D 3
  338. R 17
  339. D 10
  340. L 25
  341. U 20
  342. These motions occur as follows (individual steps are not shown):
  343. == Initial State ==
  344. ..........................
  345. ..........................
  346. ..........................
  347. ..........................
  348. ..........................
  349. ..........................
  350. ..........................
  351. ..........................
  352. ..........................
  353. ..........................
  354. ..........................
  355. ..........................
  356. ..........................
  357. ..........................
  358. ..........................
  359. ...........H.............. (H covers 1, 2, 3, 4, 5, 6, 7, 8, 9, s)
  360. ..........................
  361. ..........................
  362. ..........................
  363. ..........................
  364. ..........................
  365. == R 5 ==
  366. ..........................
  367. ..........................
  368. ..........................
  369. ..........................
  370. ..........................
  371. ..........................
  372. ..........................
  373. ..........................
  374. ..........................
  375. ..........................
  376. ..........................
  377. ..........................
  378. ..........................
  379. ..........................
  380. ..........................
  381. ...........54321H......... (5 covers 6, 7, 8, 9, s)
  382. ..........................
  383. ..........................
  384. ..........................
  385. ..........................
  386. ..........................
  387. == U 8 ==
  388. ..........................
  389. ..........................
  390. ..........................
  391. ..........................
  392. ..........................
  393. ..........................
  394. ..........................
  395. ................H.........
  396. ................1.........
  397. ................2.........
  398. ................3.........
  399. ...............54.........
  400. ..............6...........
  401. .............7............
  402. ............8.............
  403. ...........9.............. (9 covers s)
  404. ..........................
  405. ..........................
  406. ..........................
  407. ..........................
  408. ..........................
  409. == L 8 ==
  410. ..........................
  411. ..........................
  412. ..........................
  413. ..........................
  414. ..........................
  415. ..........................
  416. ..........................
  417. ........H1234.............
  418. ............5.............
  419. ............6.............
  420. ............7.............
  421. ............8.............
  422. ............9.............
  423. ..........................
  424. ..........................
  425. ...........s..............
  426. ..........................
  427. ..........................
  428. ..........................
  429. ..........................
  430. ..........................
  431. == D 3 ==
  432. ..........................
  433. ..........................
  434. ..........................
  435. ..........................
  436. ..........................
  437. ..........................
  438. ..........................
  439. ..........................
  440. .........2345.............
  441. ........1...6.............
  442. ........H...7.............
  443. ............8.............
  444. ............9.............
  445. ..........................
  446. ..........................
  447. ...........s..............
  448. ..........................
  449. ..........................
  450. ..........................
  451. ..........................
  452. ..........................
  453. == R 17 ==
  454. ..........................
  455. ..........................
  456. ..........................
  457. ..........................
  458. ..........................
  459. ..........................
  460. ..........................
  461. ..........................
  462. ..........................
  463. ..........................
  464. ................987654321H
  465. ..........................
  466. ..........................
  467. ..........................
  468. ..........................
  469. ...........s..............
  470. ..........................
  471. ..........................
  472. ..........................
  473. ..........................
  474. ..........................
  475. == D 10 ==
  476. ..........................
  477. ..........................
  478. ..........................
  479. ..........................
  480. ..........................
  481. ..........................
  482. ..........................
  483. ..........................
  484. ..........................
  485. ..........................
  486. ..........................
  487. ..........................
  488. ..........................
  489. ..........................
  490. ..........................
  491. ...........s.........98765
  492. .........................4
  493. .........................3
  494. .........................2
  495. .........................1
  496. .........................H
  497. == L 25 ==
  498. ..........................
  499. ..........................
  500. ..........................
  501. ..........................
  502. ..........................
  503. ..........................
  504. ..........................
  505. ..........................
  506. ..........................
  507. ..........................
  508. ..........................
  509. ..........................
  510. ..........................
  511. ..........................
  512. ..........................
  513. ...........s..............
  514. ..........................
  515. ..........................
  516. ..........................
  517. ..........................
  518. H123456789................
  519. == U 20 ==
  520. H.........................
  521. 1.........................
  522. 2.........................
  523. 3.........................
  524. 4.........................
  525. 5.........................
  526. 6.........................
  527. 7.........................
  528. 8.........................
  529. 9.........................
  530. ..........................
  531. ..........................
  532. ..........................
  533. ..........................
  534. ..........................
  535. ...........s..............
  536. ..........................
  537. ..........................
  538. ..........................
  539. ..........................
  540. ..........................
  541. Now, the tail (9) visits 36 positions (including s) at least once:
  542. ..........................
  543. ..........................
  544. ..........................
  545. ..........................
  546. ..........................
  547. ..........................
  548. ..........................
  549. ..........................
  550. ..........................
  551. #.........................
  552. #.............###.........
  553. #............#...#........
  554. .#..........#.....#.......
  555. ..#..........#.....#......
  556. ...#........#.......#.....
  557. ....#......s.........#....
  558. .....#..............#.....
  559. ......#............#......
  560. .......#..........#.......
  561. ........#........#........
  562. .........########.........
  563. Simulate your complete series of motions on a larger rope with ten knots. How many positions does the tail of the rope visit at least once?
  564. Your puzzle answer was 2765.