AoCG2021 Day 7: Bathroom security goes wildAoCG2021 Day 7: Bathroom security goes wild
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
The story continues from AoC2016 Day 2, Part 2.
You finally figure out the bathroom code (on the weird diamond-shaped keypad) and open the bathroom door. And then you see another door behind it, with yet another keypad design:
You're given a list of UDLR strings. Each string corresponds to one button. You start at the previous button (or button 0 at the beginning) and move to the adjacent button for each instruction, and press whatever button you're on at the end of each string. U
means to go up, D
down, L
left, and R
right, respectively. If there's no adjacent button at the given direction, you simply don't move.
Additional clarifications for some diagonal edges: For example, if you're at button 0, both U (up) and R (right) correspond to moving to button 1. The full set of rules are:
0, U or R -> 1
1, L or D -> 0
2, D or R -> 3
3, L or U -> 2
5, U or R -> 4
4, L or D -> 5
7, D or R -> 6
6, L or U -> 7
If the instructions read as ["ULL", "RRDDD", "LURDL", "UUUUD"]
, the code is as follows:
Start at 0, U: 1, L: 0, L: 0 (nowhere to move) -> 0
Start at 0, R: 1, R: 2, D: 3, D: 4, D: 5 -> 5
Start at 5, L: 6, U: 7, R: 6, D: 6, L: 7 -> 7
Start at 7, U: 0, U: 1, U: 1, U: 1, D: 0 -> 0
So the code is [0, 5, 7, 0]
.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
["ULL", "RRDDD", "LURDL", "UUUUD"] -> [0, 5, 7, 0]
["RRRR", "DLLUURR", "LDDRRUU"] -> [3, 2, 3]