When I was a kid, and wanted to count the dollar bills in my life savings, I would count out loud:
one, two, three, four, five, six, seven, eight, nine, ten;
eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;
twenty-one, twenty-two, twenty-three, twenty-four, twenty-five...
Eventually I got tired of pronouncing each of these multi-syllable numbers. Being mathematically minded, I created a much more efficient method of counting:
one, two, three, four, five, six, seven, eight, nine, ten;
one, two, three, four, five, six, seven, eight, nine, twenty;
one, two, three, four, five, six, seven, eight, nine, thirty...
As you can see, I would only pronounce the digit(s) that have changed from the previous number. This has the added advantage that it's considerably more repetitive than the English names for numbers, and therefore requires less brainpower to compute.
Challenge
Write a program/function which takes in a positive integer and outputs/returns how I would count it: that is, the right-most non-zero digit and all trailing zeroes.
Examples
1 1
2 2
10 10
11 1
29 9
30 30
99 9
100 100
119 9
120 20
200 200
409 9
1020 20
A full list of test-cases shouldn't be necessary. This is A274206 on OEIS.
Rules
- Your entry must theoretically work for all positive integers, ignoring precision and memory issues.
- Input and output must be in decimal.
- You may choose to take input and/or output as a number, a string, or an array of digits.
- Input is guaranteed to be a positive integer. Your entry can do anything for invalid input.
This is code-golf, so the shortest code in bytes wins.
[1,0,2,0]
->[2,0]
for the last test case? (I'm unclear on the phrase "single-item array"). \$\endgroup\$