 # Advent Warmup: Elvish Cheat Codes

Nov 27th, 2017
3,191
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Advent Warmup: Elvish Cheat Codes
2. ---------------------------------
3.
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.
5.
6. The sequence involves the buttons 'Up', 'Down', 'Left', 'Right', 'A', 'B', and terminates with a single press of the 'Start' button.
7.
8. The elves begin to ponder the significance of the sequence they discovered, and decide to draw a chart.
9.
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.
11.
12. -------------------------------------------------------------
13. Example: Up, A, Right, Right, B, Left, B, Start
14.
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).
16.
17. -------------------------------------------------------------
18. Example: Up, Up, Down, Down, Left, Right, Left, Right, B, A, Start
19.
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).
21.
22. -------------------------------------------------------------
23.
24. The taxicab distance ( https://en.wikipedia.org/wiki/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.
25.
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.
27.
28. Your input is here: https://pastebin.com/wGmzZHeq
29.
30. Question 1:
31.
32. Identify the marker furthest from the origin, as measured by the taxicab distance, and return that distance.
33.
34.
35. Question 2:
36.
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