challenge.txt 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --- Day 12: Rain Risk ---
  2. Your ferry made decent progress toward the island, but the storm came in faster than anyone expected. The ferry needs to take evasive actions!
  3. Unfortunately, the ship's navigation computer seems to be malfunctioning; rather than giving a route directly to safety, it produced extremely circuitous instructions. When the captain uses the PA system to ask if anyone can help, you quickly volunteer.
  4. The navigation instructions (your puzzle input) consists of a sequence of single-character actions paired with integer input values. After staring at them for a few minutes, you work out what they probably mean:
  5. Action N means to move north by the given value.
  6. Action S means to move south by the given value.
  7. Action E means to move east by the given value.
  8. Action W means to move west by the given value.
  9. Action L means to turn left the given number of degrees.
  10. Action R means to turn right the given number of degrees.
  11. Action F means to move forward by the given value in the direction the ship is currently facing.
  12. The ship starts by facing east. Only the L and R actions change the direction the ship is facing. (That is, if the ship is facing east and the next instruction is N10, the ship would move north 10 units, but would still move east if the following action were F.)
  13. For example:
  14. F10
  15. N3
  16. F7
  17. R90
  18. F11
  19. These instructions would be handled as follows:
  20. F10 would move the ship 10 units east (because the ship starts by facing east) to east 10, north 0.
  21. N3 would move the ship 3 units north to east 10, north 3.
  22. F7 would move the ship another 7 units east (because the ship is still facing east) to east 17, north 3.
  23. R90 would cause the ship to turn right by 90 degrees and face south; it remains at east 17, north 3.
  24. F11 would move the ship 11 units south to east 17, south 8.
  25. At the end of these instructions, the ship's Manhattan distance (sum of the absolute values of its east/west position and its north/south position) from its starting position is 17 + 8 = 25.
  26. Figure out where the navigation instructions lead. What is the Manhattan distance between that location and the ship's starting position?
  27. Your puzzle answer was 845.
  28. --- Part Two ---
  29. Before you can give the destination to the captain, you realize that the actual action meanings were printed on the back of the instructions the whole time.
  30. Almost all of the actions indicate how to move a waypoint which is relative to the ship's position:
  31. Action N means to move the waypoint north by the given value.
  32. Action S means to move the waypoint south by the given value.
  33. Action E means to move the waypoint east by the given value.
  34. Action W means to move the waypoint west by the given value.
  35. Action L means to rotate the waypoint around the ship left (counter-clockwise) the given number of degrees.
  36. Action R means to rotate the waypoint around the ship right (clockwise) the given number of degrees.
  37. Action F means to move forward to the waypoint a number of times equal to the given value.
  38. The waypoint starts 10 units east and 1 unit north relative to the ship. The waypoint is relative to the ship; that is, if the ship moves, the waypoint moves with it.
  39. For example, using the same instructions as above:
  40. F10 moves the ship to the waypoint 10 times (a total of 100 units east and 10 units north), leaving the ship at east 100, north 10. The waypoint stays 10 units east and 1 unit north of the ship.
  41. N3 moves the waypoint 3 units north to 10 units east and 4 units north of the ship. The ship remains at east 100, north 10.
  42. F7 moves the ship to the waypoint 7 times (a total of 70 units east and 28 units north), leaving the ship at east 170, north 38. The waypoint stays 10 units east and 4 units north of the ship.
  43. R90 rotates the waypoint around the ship clockwise 90 degrees, moving it to 4 units east and 10 units south of the ship. The ship remains at east 170, north 38.
  44. F11 moves the ship to the waypoint 11 times (a total of 44 units east and 110 units south), leaving the ship at east 214, south 72. The waypoint stays 4 units east and 10 units south of the ship.
  45. After these operations, the ship's Manhattan distance from its starting position is 214 + 72 = 286.
  46. Figure out where the navigation instructions actually lead. What is the Manhattan distance between that location and the ship's starting position?
  47. Your puzzle answer was 27016.