Starting an the origin on an infinite grid, you follow a predetermined path going up (U
), down (D
), left (L
), or right (R
). You paint every square you visit, including the square you started at and the square you finish at. Using this method, we can paint the number six using the instructions RRDDLLUUUURR
:
The origin is shown as a green star. We call this a positional encoding of the number six. Note that a positional encoding is not unique; the encoding LLUURRDDUULLUURR
also encodes the number six with some redundancy:
Note that if you visit a square you've already painted in your path, you leave it as is.
Challenge
Given a positional encoding of one of the digits zero through nine taken as a string, output which digit it encodes.
All digits will be encoded in a \$3\times5\$ format as follows:
# ### ### # # ###
# # # # # #
# ### ### ### ###
# # # # #
# ### ### # ###
### ### ### ### ###
# # # # # # # #
### # ### ### # #
# # # # # # # #
### # ### ### ###
Note that:
- The positional encoding given will always map to one of the ten digits given above exactly; the input string is guaranteed to be valid.
- The digit will never be mirrored or rotated.
- There may be redundancy in the encoding (eg
LR
). - The square you start at is always painted.
Test Cases
Input -> Output
DDDD -> 1
UUUU -> 1
DDUDDUDD -> 1
DDUUUUDDUUDD -> 1
LRRDDLLDDRLRR -> 2
LDDRRLLUURRUULL -> 2
RRDDLLRRDDLL -> 3
LLRRUULLRLRRUUDULL -> 3
LUUDDRRUUDDDD -> 4
DDLLUUDDRRDD -> 4
LLDDRRDDLL -> 5
DLLRRUULLUURRLLRR -> 5
RRDDLLUUUURR -> 6
LLUURRDDUULLUURR -> 6
RRDDLLUURRDDLLUUUURR -> 6
RRDDDD -> 7
LLRRDDDD -> 7
LUURRDDDDLLU -> 8
RUULLUURRDDLLDD -> 8
RRDDLLUURRDDDDLL -> 9
DUDLRLLRRUULLRRUULLD -> 9
RRUUUULLDDD -> 0
UUUUDDDDRRUUUULRDDDD -> 0
Also in list form:
[['DDDD', 1], ['UUUU', 1], ['DDUDDUDD', 1], ['DDUUUUDDUUDD', 1], ['LRRDDLLDDRLRR', 2], ['LDDRRLLUURRUULL', 2], ['RRDDLLRRDDLL', 3], ['LLRRUULLRLRRUUDULL', 3], ['LUUDDRRUUDDDD', 4], ['DDLLUUDDRRDD', 4], ['LLDDRRDDLL', 5], ['DLLRRUULLUURRLLRR', 5], ['RRDDLLUUUURR', 6], ['LLUURRDDUULLUURR', 6], ['RRDDLLUURRDDLLUUUURR', 6], ['RRDDDD', 7], ['LLRRDDDD', 7], ['LUURRDDDDLLU', 8], ['RUULLUURRDDLLDD', 8], ['RRDDLLUURRDDDDLL', 9], ['DUDLRLLRRUULLRRUULLD', 9], ['RRUUUULLDDD', 0], ['UUUUDDDDRRUUUULRDDDD', 0]]
Scoring
Shortest code in bytes wins.