[Question]
  [
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`:
[![](https://i.stack.imgur.com/Nv0z2.png)](https://i.stack.imgur.com/Nv0z2.png)
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:
[![](https://i.stack.imgur.com/Tkf6J.png)](https://i.stack.imgur.com/Tkf6J.png)
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.
  
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~89 ... 77~~ 71 bytes
*Saved 6 bytes by using the modulo chain provided by @KjetilS.*
```
s=>Buffer(s).map(c=>o|=p*=4**(c%5)/8,o=p=4**8)|(o/=o&-o)*321%3081%53%11
```
[Try it online!](https://tio.run/##jZPBboMwDIbvewoUiSlBaykFNnZID1OOPkXKAyAK06auQWXbqe/OSAwdJQXVQiGIjz/2b/OZ/@ZNcfqov1dHvS/bircN3739VFV5og1bf@U1LfhOn3kd8CQIaOGnLMyeNK/NY8bOVIdcP640C@Jt5MebLPLT2I@ittDHRh/K9UG/04oS0QXxJsGYF4Ze9DBhVRf3skIoe5H72C7MOuJnWJBSCAAhZLcjV@zWYTtKAiglpVIAZIlFWVwnOcSOLqCgtHeB0nOsKcpiI6ORTVwfoMcdHxI3B@RG2Q5s6ugOCRsnoPdthkVN049/e3v22c3BUKZvuCML7KB7pb/AOlOJ7MutXjj0HIvH2wQmtWVODkNROG1kkR3VdukIsq9OL5QAeRkguwoyw5rXFhiXh@zm1r9pTu@/QU96tv0D "JavaScript (Node.js) – Try It Online")
### How?
We take the ASCII code \$c\$ of the direction character modulo \$5\$ to map it to an index in \$\{0,1,2,3\}\$.
For each direction, we update a bit mask \$p\$ by shifting it by a specific amount and mark the bits that are visited in another bit mask \$o\$.
```
 char. | ASCII | mod 5 | shift
-------+-------+-------+-------
  'U'  |   85  |   0   | >> 3
  'L'  |   76  |   1   | >> 1
  'R'  |   82  |   2   | << 1
  'D'  |   68  |   3   | << 3
```
Conveniently, the shift is equivalent to multiply \$p\$ by:
$$\frac{4^{(c\bmod 5)}}{8}$$
We start with both \$p\$ and \$o\$ set to \$4^8=2^{16}\$. This value is safe because we will never right-shift by more than \$4\times 3 + 2\times 1=14\$ (e.g. with `"UUUULL"`, which draws a \$7\$, or any other path going from the bottom-right to the top-left corner). Likewise, we will never left-shift by more than \$14\$ and never exceed \$2^{30}\$. So, both \$p\$ and \$o\$ remain 32-bit values.
Because we don't know which cell in the digit was our starting point, we normalize the final value of \$o\$ by removing all trailing zeros:
```
o /= o & -o
```
We end up with a unique 15-bit key identifying the digit.
```
 digit |   binary mask   | decimal
-------+-----------------+---------
   0   | 111101101101111 |  31599
   1   | 001001001001001 |   4681
   2   | 111001111100111 |  29671
   3   | 111100111100111 |  31207
   4   | 100100111101101 |  18925
   5   | 111100111001111 |  31183
   6   | 111101111001111 |  31695
   7   | 100100100100111 |  18727
   8   | 111101111101111 |  31727
   9   | 111100111101111 |  31215
```
It can be seen as a binary representation of the digit shape rotated by 180°. For instance:
```
                       100    111
                       100    001
100 100 100 100 111 -> 100 -> 001 -> "7"
                       100    001
                       111    001
```
We apply the following function to turn it into the expected digit:
$$f(n)=\big(((n\times 321)\bmod 3081)\bmod 53\big)\bmod 11$$
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~70~~ ~~65~~ ~~63~~ ~~60~~ ~~58~~ ~~43~~ 38 bytes
```
Ｆ⁺ＳR«ＵＭＫＶＩΣκ✳ι1»≔↨ＫＡ²θ⎚§”←＆Φ⁴.º!Ｈ”﹪θ⁹⁴
```
[Try it online!](https://tio.run/##JY3LCsIwEEXX9itCVhOo4PuBq9pshCqlUvehjRpME81DBPHbY6qLCzPMmXObKzONZjKEszYISukt7NTdu6MzQl2ApAhXmKB3Mtize667jqkWSs5vJ60O3MdV9VDOrIOj7@BGCNkkgzJ@O6DC8MYJrUD0ojGOp0@SWSsuCrbM8p8pk7JXTGIeEcglZwbi8Hdkbqda/gI8X6DRarxE6@kMTXCK9rr1UsMjRetZXxpCVddFUddVRWlRUBqGT/kF "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｆ⁺ＳR«
```
Append a dummy instruction to the input to ensure that both ends get drawn, and loop over the instructions.
```
ＵＭＫＶＩΣκ
```
Pad the neighbourhood of each cell. (This is because `PeekAll()` only returns the drawn cells and not their positions, so it would be impossible to distinguish between the groups `69`, `08` and `235`.) Each orthogonally adjacent cell is replaced with its digital sum, which is `1` for cells on the path and `0` for all other cells (whether new or previously padded).
```
✳ι1»
```
Draw the path using literal `1`s and move in the appropriate direction.
```
≔↨ＫＡ²θ
```
Record which of the cells were drawn and which were just padding, and interpret that as if it was binary.
```
⎚
```
Clear the canvas.
```
§”←＆Φ⁴.º!Ｈ”﹪θ⁹⁴
```
Cyclically index the compressed lookup table `56 0817 934 2` (where the spaces are don't care values) with the base 2 number captured above modulo 94 and output the result.
It's possible to shrink the uncompressed lookup table to 11 bytes `0473125869_` by taking the number modulo 378 for the same byte count, or to 10 bytes `8739651204` by taking the number modulo 4207, but this ends up actually a byte longer after compression, so instead if you capture the number in base 5 rather than base 2, then by taking it modulo 579 you can cyclically index the result in the table `7269105348` also for the same byte count.
Example digit decoding: Drawing `RRDDDD` results in the following canvas:
```
 000
01110
 0010
  010
  010
  010
   0
```
Reading these gives `0000111000100100100100` which is 231716 in binary, then reducing modulo 94 gives 6, which (cyclically) indexed into the lookup table produces `7`, the desired result.
[Answer]
# [J](http://jsoftware.com/), 75 65 59 55 bytes
*-10 thanks to Jonah!*
*-6 thanks to Bubbler!*
*-4 thanks to FrownyFrog!*
Identifies the numbers by their bit mask of the following positions:
```
#0# 
1 2 
#3# 
4 # 
###
```
So 8 would be `11111`, and 7 would be `10100`
```
'=)76.:;4?'i.4 u:2#.1,i.@5(e.>./-:@->:)0+/\@,3-2*5|3&u:
```
[Try it online!](https://tio.run/##nZFNT4QwEIbv/IrGTWxZYFi@drW7rESJp8ZDE06aGGN2I1487UnjX8dOhwK6fiQ2UOg7M0/faZ@7E@B7VkrGWcgWTJo3Anal1XXHS3@1BLnOL3gLOTvIdAZJ2EJViB1sIY5kFW2lvwjiuyrMonRevGWnB9mxm0tgnpjJB2hhhGy530IiQrGR0QZifwfv6RxpPeE@CxzC@wvhAEnwP0R4KwOIK0GgMv6F43sI@okjqLLwX78QDS35DuftHp9emFjvfcZrM3jHuZewku37tVs0ZkwijX2mghk4o5iSqLSua6XqWpu/UTVrrVTTaN00SnEvI52SaR5EFDBL229t8/M@hHtZ1drMnRHVB1AsHIUErO6l2pHRh7L@llMf2M5EpDzsj/6Osj9XrcYg2liNzZBwNrRAiqkcxMEVnR33zo93olb6gLkIpYeDsrOpWrgq9ISgUaOrosMzMfL0AQ "J – Try It Online")
### How it works
```
3-2*5|3&u:
```
Map `DRLU` to `-3 -1 1 3`. (Thanks to Arnauld!)
```
(>./…-…)0+/\@,
```
Append 0 (the drawn starting tile), and fold every prefix to absolute indices, e.g. `0 1 2 5 8 11 14`. As an index might be negative, get the highest number and subtract it from every index.
```
i.@5(e.…-:@…>:)
```
Checks which of the indices `1 3 5 7 9` are set: `1 0 1 0 0`.
```
'=)76.:;4?'i.4 u:2#.1,
```
The bit masks with a 1 prepended (so the numbers neatly fit into ASCII) is looked up in the table.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~35~~ ~~34~~ 32 bytes
```
O%15Żı*ÄÆiḞ_Ṃ$‘ŒṬFḄ%29ị“ẆA⁻R§’D¤
```
[Try it online!](https://tio.run/##XVCxCgIxDP2XQxdxUXBwFIJTQAh0cHJyUPwBt1NEBzcnBXESXG5xO73N0w9pf6Q2yVXFUJKX5DUv7XQ8m829H9RbnVfxvDbKVbme2Pw0srdlzaX7187esr7NV/V21xZblx7tfd1zi4IeF5ce4HH25cYts6H3CQRLmokJFgKAkaMwGHtJkQgAEYAC4jwgQjSGyBjEUFGCeiagdkgiKAd5muRQiWBVUhFUKFyIE1gDVVWbvJguIT3eUdEP44/JaSXxhcoSHlPiFH3n36y4lAGkz9PEK5OV@Fr8TL5RVVXvDQ "Jelly – Try It Online")
*-1 thanks to Zgarb fixing my brainfart*
*-2 thanks to Jonathan Allan reminding me of `Ż` and rearranging to remove a space*
I have no idea what I'm doing... Going all the way through `Ḟ‘ŒṬ` feels like it may not be necessary with a smart choice of hash function, and it's not a terrible idea to just try translating Arnauld's JS answer outright. I've tried quite a few dumber hash functions, and they've all gotten tripped up on 2 versus 5, but maybe if I keep using base conversion...
```
       Ä          Cumulative sums of
     ı*           sqrt(-1) to the (vectorized) power of
O                 the codepoints of the input
 %15              mod 15 (U,D,L,R -> 10,8,1,7 ≡ 2,0,1,3 mod 4)
    Ż             with 0 prepended.
        Æi        a + bi -> [a, b],
          Ḟ       convert the floats to integers,
           _Ṃ$    and subtract the minimum.
‘                     Increment so that all indices are positive,
 ŒṬ                   then convert them to a multidimensional Boolean array,
   F                  flatten it,
    Ḅ                 convert from binary,
     %29              mod 29,
        ị             modular index into
                D¤    the decimal digits of
         “ẆA⁻R§’      813540020976.
```
[Answer]
# [Perl 5](https://www.perl.org/), ~~96~~ 84 bytes
```
$s=0 x99;substr$s,$p+=ord()*9%45%7-3,1,1for$p=49,@F;$s=~/1.*1/;$_=$&*8%29014%1637%11
```
[Try it online!](https://tio.run/##VVDBasMwDL37K0qxx5ama72ma00I7CB60sngc9nYBoOymLiFnfbp8/zsNFBhpCfp6Vm2/xhO2xhl6NazH2PacHkL50GGWvpF1w/v9w@VUc1W7ZabWtf6sx@k7xpTvxzaNPO70o@VXrXy2Mm7aq@ezFo3Sj9vdkrrGCmZcMkEkcsHIBl8SthaImYim5BAtMzOWescsyjN4gUAqjZHQp@hkTPKwjwWIMwFJBZdJ6ELPOpiDVya69inoKl7w0KSZa@g9DNDTOrlLTcKZQVHbKcHZA8WtDFQvgjcsZbn/np//uq/Q1y@@tNhPv8H "Perl 5 – Try It Online")
Somewhat ungolfed:
```
cat <<'.' > recognise.pl
$s=0 x99;                                   #init string of 100 zeros
substr$s,$p+=ord()*9%45%7-3,1,1for$p=49,@F; #replace 0 with 1 for each step of
                      #input char, start at pos 49, -3 for U, 3 for D, -1 for L,
                      #1 for R. ord() is ascii val of UDLR
$s=~/1.*1/;           #find longest substring that starts and ends with 1, treat
                      #that string as a long int, i.e. 8 = 111101111101111
$_=$&*8%29014%1637%11 #modulus voodoo to get the digit
.
cat <<. | perl -F"" -apl recognise.pl
DDDD
UUUU
DDUDDUDD
DDUUUUDDUUDD
LRRDDLLDDRLRR
LDDRRLLUURRUULL
RRDDLLRRDDLL
LLRRUULLRLRRUUDULL
LUUDDRRUUDDDD
DDLLUUDDRRDD
LLDDRRDDLL
DLLRRUULLUURRLLRR
RRDDLLUUUURR
LLUURRDDUULLUURR
RRDDLLUURRDDLLUUUURR
RRDDDD
LLRRDDDD
LUURRDDDDLLU
RUULLUURRDDLLDD
RRDDLLUURRDDDDLL
DUDLRLLRRUULLRRUULLD
RRUUUULLDDD
UUUUDDDDRRUUUULRDDDD
.
```
[Answer]
# [R](https://www.r-project.org/), 314 bytes
Not very short unfortunately, feels like the extra illegibility isn't worth it here.
```
{f=pryr::f
f(w,{s=switch
l=f(t,t[length(t)])
a=f(t,s=0,c(t,l(t)+s))
v=f(c,s(c,U=-1,D=1,0))
h=f(c,s(c,L=-1,R=1,0))
m=f(l,b,x=0,{for(c in l)x=a(x,b(c))
    x})
z=el(strsplit(w,''))
x=m(z,h)
y=m(z,v)
p=x-min(x)
q=y-min(y)
r=p+q*3
u=unique(r)
d=trunc(10*(var(u)+median(u)))%%28
match(d,c(0,5,20,3,2,16,1,26,8,19))-1})}
```
[Try it online!](https://tio.run/##hVLBbqMwEL37K5BWVexmIgHZpGkl9@SjT0g@VXugBBIkoAmYlDTKt6djExLSJeoIzOi95/G8MeVpFetlukq1w53TIeGbcl@@vCQkoZ9wqHj1mepoTTKeUA36LYuLlV5Tzf4xElqs4i5E@M0QHFeMkR3CEVT4Kj7xQHAPXITXF1gaODjDOcIZvEODZQ7JR0kjJy2cjDU8pA280wg1DkZzZOSLxxmtdFltslRje6MRkg3P6ResGdnbZMfIhjeTPC1ow8iW7226Z6Tkm/H2cUpqXhfpto5pyciS67IuIuq5j3QXlrRm4zxepmGBGWMPD/6C5CHap0u06MIMfBem4IM3Bw/8OSzAe2Zs4h3Z8TJGOhIYI@b8cSavjkeuuMIYwoVQ9rnDYZh1mJdBIISUQgSYdQK/L0AqkFKpIFBKyiFJW6JdO37aLyHbvYH9CnVHZVq0gp79vzdW5FkzzFsXN03M@ru7LowT2TM7@8@JmdiVn98cYRgzzTYb0nQ1fqtl@KuRpx/zusu1hW3pjl/0q3attbc6KOk12J/Wc39aSsjgcm92FUM6Q1nyepT74481h5xlN67c0zc "R – Try It Online")
Intermediate calculations from:
```
letters=list(
x1=c(0,3,6,9,12),
x2=c(0,1,2,5,6,7,8,9,12,13,14),
x3=c(0,1,2,5,6,7,8,11,12,13,14),
x4=c(0,2,3,5,6,7,8,11,14),
x5=c(0,1,2,3,6,7,8,11,12,13,14),
x6=c(0,1,2,3,6,7,8,9,11,12,13,14),
x7=c(0,1,2,5,8,11,14),
x8=c(0,1,2,3,5,6,7,8,9,11,12,13,14),
x9=c(0,1,2,3,5,6,7,8,11,12,13,14),
x0=c(0,1,2,3,5,6,8,9,11,12,13,14)
)
sapply(letters,function(letter){trunc(10*(var(letter)+median(letter)))%%28})
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~31~~ 28 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Yes, it's very similar to [Unrelated String's](https://codegolf.stackexchange.com/a/211016/53748), but it's slightly different and was completely independently found.
```
O%15Żı*ÄÆi_Ṃ$QṢ“X|cE’Dṭ⁽½ȯ¤ḥ
```
**[Try it online!](https://tio.run/##VVCxCsIwEN3zHbq4OfgH53YgBgJuDuKg9AcEh1pEv0FwEt0UERwspUur4G@kPxLzLm3BI9y9u3v3cslyHkUr50bd/uCTvR@9clvuFlObJp2xTU9VfJysZ8MqPpBNb9UmL/LvvTjb18XZ7Fnuq@TqHHlTxpsiMnIAvMH7hLUmYibSHilEzWyM1sYwq9AMXgGgqiUS@gwNyUiEuS5AmAPwLGomoQtc62INXCp17BNQ2/1jIRHZBoS@MFSrHt7ypxBWMMS6fYB4sKCNgfBF4NY1mfsB "Jelly – Try It Online")**
If a larger salt (which is also less than \$250^6\$) for the hash built-in is found which removes the need to permute \$[0,9]\$ (making `“X|cE’Dṭ⁽½ȯ¤ḥ` become `“?????’,⁵¤ḥ’`) we get 27 (or less).
### How?
```
O%15Żı*ÄÆi_Ṃ$QṢ“X|cE’Dṭ⁽½ȯ¤ḥ - Link: listof characters
O%15                         - mod 15 of ordinals
    Ż                        - prepend a zero
     ı*                      - root(-1) raised to each of those
       Ä                     - cumulative sums
        Æi                   - convert each to [real, imaginary]
          _Ṃ$                - subtract of the minimum from each
             Q               - distinct values
              Ṣ              - sort
                          ¤  - nilad followed by link(s) as a nilad:
               “X|cE’        -   1398462570
                     D       -   to decimal digits (our domain)
                       ⁽½ȯ   -   3742 (our salt)
                       ṭ     -   tack -> [3742,[1,3,9,8,4,6,2,5,7,0]]
                           ḥ - hash (the sort results using that [salt, domain])
```
---
Previous version at 31 bytes using no built-in hash function...
```
O%15Żı*ÄÆi_Ṃ$QṢFḞḌ%⁽¥Ƭị“ċḞƒø’D¤
```
A monadic Link accepting a list of characters which yields an integer in \$[0,9]\$.
**[Try it online!](https://tio.run/##VVAxCsJAEOzvHdrYWfiDxWpBPLjaykLxA3ZRRItY2QliIdqlESwiwSbR/OPykfNmLwlkOfZmZ2cne1nOV6u1c5P@cPTLvs9BsSv2i5l9b3tT@76NbXq16bFfbT75o0xsFlfR5Rt7tjwVaRWdKb87m72KQ7VNnCMfyvhQREYOgA9kX7DWRMxE2iOFWzMbo7UxzCo0Q1YAYLXchD7DQyoSY64JGHMAXkXNJHyBa1@sgY8Kj30CarsdFQqxbUDoi0K17uEtHYewgiHW7QMkQwVvDIRfBG3Nydwf "Jelly – Try It Online")**
### How?
```
O%15Żı*ÄÆi_Ṃ$QṢFḞḌ%⁽¥Ƭị“ċḞƒø’D¤ - Link: listof characters
O%15Żı*ÄÆi_Ṃ$QṢ                 - as above
               F                - flatten
                Ḟ               - floor (so Ḍ gives an integer rather than a float)
                 Ḍ              - convert from base ten
                  %⁽¥Ƭ          - modulo 2153
                       “ċḞƒø’D¤ - decimal digits of 3652914780
                      ị         - 1-indexed modulo index into
```
[Answer]
# [R](https://www.r-project.org/), ~~217~~ ~~200~~ 192 bytes
(or only **[169 bytes](https://tio.run/##jZNfa8IwFMXf/RTiCCQugml1q0L3lJdBnsL6JN0crUphRmcb0I19dpd/utpGWSgxhd89nntuujvuFtlmJYqvxVterIoqPi6lyKpiI2CJZSyrZfSyeRYV@s7j8n27/TjADA6xhCVCeA4KAeZ4H0vYozxhPYQ6IrZUPiPTAKeDfBZORzjFBJ@F9wge4kyuS7lWZzRYFwIeVKl@D16lKD7lAoZ9McMkvVd7kKJ@GBAEQDiMCADjEABCfprWlQe1eqjbWHfdwVOXdFp0otb/aUoT81xW3KDV0nu9wtFtnHFOKWOUcnU68wYPPLTiOGNJwnmSMOZ4R7dxq233hpfQI86sKje/1Ok72oPrDg1Zz97gI18szBW0Yhn5xJlF674dPvaIn6zrYNgpSEdfi0WPqRa5xR98VjSnB2pPtuIafdK@/A9H@/H2zTX4o39Cbd7R3glZXhlp9Bl5rJwatPexfreizu1G/@Zk8IlnQgll/HzBzE5dLBOvuE5O26j3avCh/3PWJlyVi8jRx18)** by stealing Arnauld's modulo chain to get the final digit without a look-up table...)
```
function(s,u=utf8ToInt){d=sapply(c(0,u(s)),`%in%`,x=u("DRUL"))
n=apply(d[1:2,]-d[3:4,],1,function(x)(y=cumsum(x))-min(y))
match(sum(2^unique(n[,1]+5*n[,2]))%%27%%11,c(0,4,7,10,8,5,2,3,9,1))-1}
```
[Try it online!](https://tio.run/##jZNda8IwFIbv/RXiKCTbEUyt8wO6q9wMchXWK@mm1I8V1ui0Ad3Yb3f50lUbZaGkoTzn9T3viZvDZp6tliL/mr/N8mVexoeFFFmZrwTagoxluRi8rJ5Fib9n8Xa6Xn/sUYY6INEWY5gEuQgmsIslalGesBbGDRFbajYmoxDS9mzcHUWQAoGT8A6jfZzJYisLdcbtIhdor0qLaZm9I/01fJUi/5RzJMZA0ofevXqHKcZBEPaDgBDQHiLoA@nAAHoQQheGQJQW@bnsSFlTq4WbF@uu2X5qkkaNTtT6P01pYp7zihu0WnqvVji6jjPOKWWMUq5OJ97goYdWHGcsSThPEsYc7@g6brXtfuGl6xFnVpWbN3X6jvbgukNDVrM3eOSLhbmCWiyRT5xZtOrb4T2P@NG6DoYdg3T0tVj0mCqRW/zRZ0VzeqD2ZCuu0Uft899wtB@v31yD9/0TqvOO9k7I8srIRZ8Dj5Vjg/Y@Vu/WoHG70b85GXzomVBCGT9dMLNTF8vQK66T0zaqvRq84/87axOuykXk6MMv "R – Try It Online")
**How?**
Original code (before significant golfing changes...):
```
recognize_digit=
function(s){
                                # first we 'construct' the digit from the encoding:
                                
 d=sapply(                      # d is direction of each step, calculated by...
    c("D","R","U","L"),         # ...using each letter...
    grepl,                      # ...as a regex...
          el(strsplit(s,'')))   # ...to search each letter of the encoding.
 m=matrix(!-40:40,9)            # m is a matrix big enough to fit the letters (9x9)
 m[                             # we set the elements of m, selected by...
   apply(d[,1:2]-d[,3:4],       # ...subtracting L from R, and U from D...
   2,                           # ...and for each of the L-R and U-D columns...
   cumsum)+5                    # ...calculating the cumulative sum +5, 
            ]=T                 # to 'TRUE'.  
 l=m[(c=t(which(m,T)))[1]+0:4,  # l is the 3x5 'letter' matrix, starting at the  
   c[2]+0:2]                    # first TRUE elment of m
                                
                                # now we have the digit in l, so we just have to
                                # recognize it: 
 match(                         # we find the match between...
  sum(l*2^(0:14))               # the number formed by using the pixels of the digit as bits...
   %%27%%11,                    # MOD 27 MOD 11 (reduces each number to a smaller number
  c(0,4,7,10,8,5,2,3,9,1))-1    # and the 'lookup' table of results for each digit.
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~36~~ 35 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
•7‡šмÓ•žFDIÇv4y5%m8/*DŠ~s}\b0ÚC45%è
```
Port of [*@Arnauld*'s 78 bytes version](https://codegolf.stackexchange.com/revisions/211013/10), so make sure to upvote him as well! (His 78→77 and 77→71 golfs would be longer in 05AB1E.)
[Try it online](https://tio.run/##yy9OTMpM/f//UcMi80cNC48uvLDn8GQg5@g@NxfPw@1lJpWmqrkW@louRxfUFdfGJBkcnuVsYqp6eMX//y6hLj5BPj5BQaGhMNIFAA) or [verify all test cases](https://tio.run/##XU8xCsJAEPyKHNiIoIWinYWL1VYHV6mFAQsLsRACKZRU2mtnZax8hNiE9L4hH4m3O55KQrib2Z2bnd1sF9FqWcXJyDTKw6lhRlWZ3gZlmhXZ65GfPSmeE0ryY9xL@s31sNOi4rrf7mZRN7@Me/1mfq/a1dRY6/zHTESmbQR7RJ@qJZTp11Xm9AfUFw6UrX8hXtYj4eLE7Jz4MfsKBDhFwOhYvQkaFjflYTp/ShjCgKql4CAzGFPRlGAIoT3JCPSnqClt2BcJAaFSnUiCC/aseYVQjth@V9OTzPwN).
**Explanation:**
```
•7‡šмÓ•              # Push compressed integer 31846207905
 žF                  # Push builtin 16384 (2**14)
   D                 # Duplicate it
    I                # Push the input-string
     Ç               # Convert it to a list of codepoint integers
      v              # Loop over each codepoint `y`:
        y5%          #  Take `y` modulo-5
       4   m         #  Take 4 to the power this value
            8/       #  Divide it by 8
              *      #  Multiply it by the top of the stack
               D     #  Duplicate it
                Š    #  Tripleswap (a,b,c → c,a,b) the top three values on the stack
                 ~   #  Bitwise-OR the top two
                  s  #  And swap so the other value is at the top again
      }\             # After the loop: discard the top value
        b            # Convert the integer to binary
         0Ú          # Remove all leading/trailing 0s
           C         # Convert it from binary back to an integer
            45%      # Modulo-45
               è     # And index it into the digits of 31846207905 (0-based modulair)
                     # (after which the digit is output implicitly as result)
```
[See this 05AB1E tip of mine (section *How to compress large integers?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `•7‡šмÓ•` is `31846207905`.
[Answer]
# Batch 207 bytes
Notes:
* *must be run from the command line using:* `Echo(NoP pattern|Cmd /V:on`
*where `pattern` is a list of movements IE*: `D D D D R R U U U U L L`
* **requires windows 10 with virtual terminal support**
* `ESC` is a stand in for the ANSI escape character, [As it can't be pasted here, the scripts raw paste data can be found here](https://pastebin.com/Ayg61EDx).
	+ Or it can be generated by opening the command prompt and typing:
		- `>"%TEMP%\escape.chr" Echo(``ALT`+`027` then pressing `ENTER`
	+ Or output using a for loop with `Echo off`:
		- `(For /F "skip=4 DELIMS=" %a in ('Echo(prompt $E^|cmd')Do Echo(%a) >"%TEMP%\escape.chr"`
filename: NoP
```
@Echo off&Set $=Set &cls
%$%U=A&%$%D=B&%$%R=C&%$%O=^<nul set/P =&%$%E=echo(&%$%"F=|findstr /C:"L" >nul &&"
%O%ESC[6;7H*ESCD
For %%c in (%*)do %e%%%c%F%%O%ESC[2D*||%e%%%c%F:"L"="R"%%O%*||%O%ESC!%%c!*ESCD
%e%ESC[12;1H
```
How: the input is assessed using findstr and converted to the [virtual terminal sequences](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#cursor-positioning) required to move the cursor accordingly using sequential `&&` and `||` conditional tests, akin to a compound series of if / else statements.
]