4 minor formatting changes
source | link

GNU sedGNU sed, 17 14 + 1(r flag) = 15 bytes

Edit: -2 bytes thanks to RileyEdit: 2 bytes less thanks to Riley

s:.*([^0]):\1:

It works by deleting everything until the right-most nonzero digit, which is then printed along with possibleany existing trailing zeros. The script can also handle multiple inputs,tests in one perrun, each on a separate line.

Try it online! (all test examples)

GNU sed, 17 14 + 1(r flag) = 15 bytes

Edit: -2 bytes thanks to Riley

s:.*([^0]):\1:

It works by deleting everything until the right-most nonzero digit, which is then printed along with possible trailing zeros. The script can also handle multiple inputs, one per line.

Try it online! (all test examples)

GNU sed, 17 14 + 1(r flag) = 15 bytes

Edit: 2 bytes less thanks to Riley

s:.*([^0]):\1:

It works by deleting everything until the right-most nonzero digit, which is then printed along with any existing trailing zeros. The script can handle multiple tests in one run, each on a separate line.

Try it online! (all test examples)

3 shorter solution
source | link

GNU sed, 1617 14 + 1(r flag) = 1715 bytes

Edit: -2 bytes thanks to Riley

s:.*([^0]0*[^0]):\1:

It works by deleting everyhtingeverything until the right-most nonzero digit that, which is followed bythen printed along with possible trailing zeros or nothing at all. The script can also handle multiple inputs, one per line.

Try it online!Try it online! (all test examples)

GNU sed, 16 + 1(r flag) = 17 bytes

s:.*([^0]0*):\1:

It works by deleting everyhting until the right-most nonzero digit that is followed by trailing zeros or nothing at all. The script can also handle multiple inputs, one per line.

Try it online! (all test examples)

GNU sed, 17 14 + 1(r flag) = 15 bytes

Edit: -2 bytes thanks to Riley

s:.*([^0]):\1:

It works by deleting everything until the right-most nonzero digit, which is then printed along with possible trailing zeros. The script can also handle multiple inputs, one per line.

Try it online! (all test examples)

2 better explanation
source | link

GNU sed, 16 + 1(r flag) = 17 bytes

s:.*([^0]0*):\1:

It works by deleting everyhting until the right-most nonzero digit that is followed by trailing zeros or nothing at all.

Test examples: the The script can also handle multiple inputs, one per line.

sed -rf efficient_count.sed << EOF
> 2
> 10
> 11
> 30
> 99
> 100
> 120
> 200
> EOF
2
10
1
30
9
100
20
200

Try it online! (all test examples)

GNU sed, 16 + 1(r flag) = 17 bytes

s:.*([^0]0*):\1:

It works by deleting everyhting until the right-most nonzero digit that is followed by trailing zeros or nothing at all.

Test examples: the script can handle multiple inputs, one per line

sed -rf efficient_count.sed << EOF
> 2
> 10
> 11
> 30
> 99
> 100
> 120
> 200
> EOF
2
10
1
30
9
100
20
200

GNU sed, 16 + 1(r flag) = 17 bytes

s:.*([^0]0*):\1:

It works by deleting everyhting until the right-most nonzero digit that is followed by trailing zeros or nothing at all. The script can also handle multiple inputs, one per line.

Try it online! (all test examples)

1
source | link