# Efficient counting

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 , so the shortest code in bytes wins.

• So does "in decimal" include a list of decimal digits, like [1,0,2,0] -> [2,0] for the last test case? (I'm unclear on the phrase "single-item array"). – Jonathan Allan Feb 21 '17 at 23:26
• @JonathanAllan By "single-item array" I meant an array that contains a single number or string which represents the integer. I didn't think allowing arrays of digits was a good idea, but now it kind of seems like an arbitrary restriction since strings are allowed (and strings are very similar to arrays in many languages). So I'll allow an array of digits unless there's a good reason not to. – ETHproductions Feb 21 '17 at 23:38
• Dang it, you stole my secret :P – LegionMammal978 Feb 22 '17 at 2:07
• I think almost everyone counted like this as a kid. ;) At least I did as well. :) – Kevin Cruijssen Feb 22 '17 at 8:35
• @KevinCruijssen "as a kid"? – Martin Ender Feb 22 '17 at 8:55

## Batch, 88 bytes

@set/ps=
@set z=
:l
@if %s:~-1%==0 set z=0%z%&set s=%s:~,-1%&goto l
@echo %s:~-1%%z%


Takes input on STDIN.

->n{n[/.0*$/]}  Input is a string (allowed by the rules) # Haskell, 38 bytes x!d|m<-mod x d,m>0=m|e<-10*d=x!e (!10)  Try it online! Usage: (!10) 1020 yields 20. Explanation: x!d is a recursive formula which computes x modulo d with initially d=10. If the result is larger zero it is returned, otherwise recursively x!(10*d) is called. Other approaches: (39 bytes) x!d|m<-xmod10^d,m>0=m|e<-1+d=x!e;(!1) f x=[y|y<-[xmod10^e|e<-[1..]],y>0]!!0 f x=[y|y<-map(mod x.(10^))[1..],y>0]!!0  # Java 8, 33 bytes s->s.replaceAll(".*?(.0*)$","$1")  I/O as a String. Try it online. Explanation: s-> // Method with String as both parameter and return-type s.replaceAll(".*?(.0*)$", //  Replace all occurrences of this match,
"$1") // with this replacement  Regex explanation: .*?(.0*)$                   // MATCH:
.*?                         //  Zero or more optional characters
//  (the optional is used to give other 0+ matches
//   higher priority/precedence)
.                       //  Followed by any character
0*                     //  Followed by zero or more literal 0s
$// At the end of the string ( ) // And capture those non-optional characters in capture group 1$1                          // REPLACEMENT:
//  The content of capture group 1, which basically removes
//  the optional characters outside the capture group