Advent Warmup: Elvish Cheat Codes

Sorceress Nov 27th, 2017 (edited) 2,466 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Advent Warmup: Elvish Cheat Codes
  2. ---------------------------------
  4. In the run up to advent, the elves are playing on their video game console. Before long, one of the elves manages to discover a cheat mode, by entering a sequence of button presses on the controller.
  6. The sequence involves the buttons 'Up', 'Down', 'Left', 'Right', 'A', 'B', and terminates with a single press of the 'Start' button.
  8. The elves begin to ponder the significance of the sequence they discovered, and decide to draw a chart.
  10. Starting at the origin in an (x,y) grid, the buttons Up, Down, Left, Right are imagined to move a cursor a single step in the corresponding direction through the grid. Buttons A and B place corresponding markers at the current cursor location.
  12. -------------------------------------------------------------
  13. Example:  Up, A, Right, Right, B, Left, B, Start
  15. Taking Right to be the positive x direction, and Up to be the positive y direction. This sequence will move one step up from the origin (0,0), and place an 'A' marker at location (0,1), then a 'B' marker at location (2,1). The cursor will move one step left and another 'B' marker is placed at location (1,1). Then the cursor halts at location (1,1).
  17. -------------------------------------------------------------
  18. Example:  Up, Up, Down, Down, Left, Right, Left, Right, B, A, Start
  20. Again, starting from the origin (0,0), this sequence will place both a 'B' and an 'A' marker at (0,0), and the cursor will halt at (0,0).
  22. -------------------------------------------------------------
  24. The taxicab distance ( ) between two grid locations is defined as the (positive) difference between the two points' x values + the (positive) difference between their y values.
  26. eg, between locations (1,2) and (8,6), the difference between the two x values (1 and 8) is 7, and the difference between the two y values (2 and 6) is 4. Therefore, the taxicab distance is 7 + 4 = 11.
  28. Your input is here:
  30. Question 1:
  32. Identify the marker furthest from the origin, as measured by the taxicab distance, and return that distance.
  35. Question 2:
  37. Consider all pairs of *different* markers (where a pair may consist of any 'A' and any 'B' marker). Identify the pair maximally far apart from one another, as measured by the taxicab distance, and return that distance.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand