Byte count assumes ISO 8859-1 encoding.
10$*
1
,1$`
,1+
$_¶
(?<=(¶?.+)+)1
$#1$*
1{10}1?
,(1*)
$.1
Try it online!
Explanation
Another implementation of the ... % 11 % 10 algorithm. The fun part of doing it with a regex is that we can take care of both modulo computations at once.
10$*
Initialise the string to ten 1
s.
1
,1$`
Replace each of those with a comma, a one, and the prefix in front of that one. This gives ,1,11,...,1111111111
, i.e. a unary range.
,1+
$_¶
Now replace each of the range elements with the entire string followed by a linefeed. This gives us a 10x10 grid of unary numbers indicating the current column.
(?<=(¶?.+)+)1
$#1$*
Match each 1
and determine which row it's on by repeating group one that many times. Replace the 1
with that many 1
s. This multiplies the values in each row by the row's 1-based index.
1{10}1?
Now let's do mod 11, mod 10 in one step. To do mod 11, we'd normally just remove all 1{11}
from the string to be left with the remainders. And then we'd remove 1{10}
after that. But if we just remove ten 1
s plus another if possible, the regex engine's greediness will do mod 11 for us as long as possible, and if not, then it'll try at least mod 10.
,(1*)
$.1
Finally, we just convert each number to decimal by replacing it with its length.