[Question]
  [
On 4chan, a popular game is get. Every post on the site gets a sequential post ID. Since you can't influence or determine them, people try to guess (at least a part of) their own post number, usually the first few digits. Another version of the game is called dubs, and it's goal is to get repeating digits at the end of the number (i.e 1234555).
Your task, if you wish to accept it, is to write a program that takes a post id as input (standard integer, you can assume below 2^32), and returns how many repeating digits are on the end.
# Rules
* Standard loopholes are **disallowed**.
* The program can be a function, full program, REPL command, whatever works, really, as long as no external uncounted code/arguments are needed to run it.
* Input can come from STDIN, function arguments, command line argument, file, whatever suits you.
# Test Cases
```
Input: 14892093
Output: 1
Input: 12344444
Output: 5
Input: 112311
Output: 2
Input: 888888
Output: 6
Input: 135866667 //Post number I got on /pol/ few days ago, rip
Output: 1
```
  
[Answer]
## Mathematica, 29 bytes
How about an arithmetic solution?
```
IntegerExponent[9#+#~Mod~10]&
```
I'm very pleased to see that this beats the straight-forward Mathematica approach.
### Explanation
The code itself computes **9\*n + n%10** and then finds the largest power of **10** that divides the input, or in other words, counts the trailing zeros. We need to show if **n** ends in **k** repeated digits, that **9\*n + n%10** has **k** trailing zeros.
Rep-digits are most easily expressed mathematically by dividing a number like **99999** (which is **105-1**) by **9** and then multiplying by the repeated digit. So we can write **n = m\*10k + d\*(10k-1)/9**, where **m ≢ d (mod 10)**, to ensure that **n** doesn't end in *more* than **k** repeated digits. Note that **d = n%10**.
Let's plug that into our formula **9\*n + n%10**. We get **9\*m\*10k + d\*(10k-1) + d**. The **d** at the end is cancelled, so we're left with: **9\*m\*10k + d\*10k = (9\*m + d)\*10k**. But **9 ≡ -1 (mod 10)**, so **9\*m + d ≡ d - m (mod 10)**. But we've asserted that **m ≢ d (mod 10)** and hence **d - m ≢ 0 (mod 10)**. 
In other words, we've shown that **9\*m + d** is not divisible by **10** and therefore, the largest power of **10** that divides **9\*n + n%10 = (9\*m + d)\*10k** is **k**, the number of trailing repeated digits.
As a bonus, this solution prints the correct result, `∞`, for input `0`.
[Answer]
## [Retina](https://github.com/m-ender/retina), 9 bytes
```
&`(.)\1*$
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/ivlqChpxljqKXy/7@hiYWlkYGlMZehkbEJEHAZAhmGhlwWYMBlaGxqYQYE5goA "Retina – TIO Nexus")
Counts the number of overlapping matches of `(.)\1*$` which is a regex that matches a suffix of identical characters.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 4 bytes
```
ẹḅtl
```
[Try it online!](https://tio.run/nexus/brachylog2#@/9w186HO1pLcv7/NzQyNgGB/1EA "Brachylog – TIO Nexus")
### Explanation
```
ẹ       Elements: split to a list of digits
 ḅ      Blocks: group consecutive equal digits into lists
  t     Tail: take the last list
   l    Length: Output is the length of that last list
```
If `ḅ` worked directly on integers (and I'm not sure why I didn't implement it so that it does), this would only be 3 bytes as the `ẹ` would not be needed.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~47~~ 41 bytes
```
lambda s:len(`s`)-len(`s`.rstrip(`s%10`))
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqhQbJWTmqeRUJygqQtl6BUVlxRlFgCZqoYGCZqa/wuKMvNKFNI0MvMKSks0gAKGhkbGhoYA "Python 2 – TIO Nexus") 
### 36 bytes - For a more flexible input
```
lambda s:len(s)-len(s.rstrip(s[-1]))
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqhQbJWTmqdRrKkLpvSKikuKMgs0iqN1DWM1Nf8XFGXmlSikaWTmFZSWaAAF1A0NjYwNDdUB "Python 2 – TIO Nexus")
[Answer]
## Javascript (ES6), ~~55~~ ~~52~~ ~~32~~ 30 bytes
```
a=>a.match`(.)\\1*$`[0].length
```
* Saved **19** bytes thanks to @MartinEnder by replacing the regex
* Saved **2** bytes thanks to @user81655 using tagged templates literals
---
Using a regex to match the last group of the last digit
*Note: First time posting. Do not hesitate to make remarks.*
```
f=a=>a.match`(.)\\1*$`[0].length
console.log(f("14892093"));//1
console.log(f("12344444"));//5
console.log(f("112311"));//2
console.log(f("888888"));//6
console.log(f("135866667 "));//1
```
[Answer]
# [Perl 5](https://www.perl.org/), 22 bytes
21 bytes of code + `-p` flag.
```
/(.)\1*$/;$_=length$&
```
[Try it online!](https://tio.run/nexus/perl5#U1YsSC3KUdAtyPmvr6GnGWOopaJvrRJvm5Oal16SoaL2/79nXkFpiZWCoYmFpZGBpTGXoZGxCQhwGQJZhoZcFmDAZWhsamEGBOYA "Perl 5 – TIO Nexus")
`/(.)\1*$/` gets the last identical numbers, and then `$_=length$&` assigns its length to `$_`, which is implicitly printed thanks to `-p` flag.
[Answer]
# C, ~~62~~ ~~56~~ ~~48~~ 47 bytes
*Saved a byte thanks to @Steadybox!*
```
j,k;f(n){for(k=j=n%10;j==n%10;n/=10,k++);k-=j;}
```
[Try it online!](https://tio.run/nexus/c-gcc#@5@lk22dppGnWZ2WX6SRbZtlm6dqaGCdZQuh8/RtDQ10srW1Na2zdW2zrGv/5yZm5mloVhcUZeaVpGkoqabE5KFiJR2uNA1DEwtLIwNLY00wx8jYBAQgHCDP0BDMtAADiKixqYUZEJhragLtAAA "C (gcc) – TIO Nexus")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~38~~ 32 bytes
```
f=lambda n:0<n%100%11or-~f(n/10)
```
*Thanks to @xnor for saving 6 bytes!*
[Try it online!](https://tio.run/nexus/python2#HczBCsIwEIThsz7FXJY2kOJuUzUp6rtUQqCgWwmeffW4@p3@uUwr18fyvOcFOvNFSZhJZKvDp/R6EHatbBWKVSFTTCOn4CFjmH6sLEU84p/tcIwnc573u1dd9Y2OUsZwA@UOhF497Ni59gU "Python 2 – TIO Nexus")
[Answer]
# PHP, 47 45 40 bytes
```
while($argn[-++$i]==$argn[-1]);echo$i-1;
```
Run with `echo <n> | php -nR '<code>`
seems a loop is still smaller than my first answer. simply count the chars that are equal to the last. This uses negative string offsets of *PHP 7.1*.
*-5 bytes* by Titus. Thanks !
---
Old answer:
```
<?=strlen($a=$argv[1])-strlen(chop($a,$a[-1]));
```
removes from the right every character matching the rightmost character and calculates the difference in the length.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
.¡¤g
```
[Try it online!](https://tio.run/nexus/05ab1e#@693aOGhJen//xsaGZsAAQA "05AB1E – TIO Nexus")
or as a [Test suite](https://tio.run/nexus/05ab1e#qymr/K93aOGhJen/K5UO77dSOLxfSee/oYmFpZGBpTGXoZGxCRBwGQIZhoZcFmDAZWhsamEGBOYA)
**Explanation**
```
.¡    # group consecutive equal elements in input
  ¤   # get the last group
   g  # push its length
```
[Answer]
## [CJam](https://sourceforge.net/p/cjam), 7 bytes
```
re`W=0=
```
[Try it online!](https://tio.run/nexus/cjam#K/TTr7YKsv4flJoQbmtg@z82r1b/v6GJhaWRgaUxl6GRsQkQcBkCGYaGXBZgwGVobGphBgTmAA "CJam – TIO Nexus")
### Explanation
```
r   e# Read input.
e`  e# Run-length encode.
W=  e# Get last run.
0=  e# Get length.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
DŒgṪL
```
[Try it online!](https://tio.run/nexus/jelly#@@9ydFL6w52rfP7//29oZGwCBAA "Jelly – TIO Nexus")
**Explanation**
```
D      # convert from integer to decimal   
 Œg    # group runs of equal elements
   Ṫ   # tail
    L  # length
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~32~~ 29 bytes
```
f(x){x=x%100%11?1:-~f(x/10);}
```
This is a port of [my Python answer](https://codegolf.stackexchange.com/a/114241/12012).
This work with gcc, but the lack of a `return` statement is undefined behavior.
[Try it online!](https://tio.run/nexus/c-gcc#HYzRCoJAFESfd79iEBZ2baW9aqaJ9SHVQ6CSUEuEkCD263a38zQzzMza68nMUzMpck4RneiQfDnbkjP1sg5@xPM2eG3kLEVw47m4osFMeVmlrsosKM3yACuWRBblH/bZriyY/WIRe16NtZTicx8eHXTsjRTi9ebTXkeqapEcodqLj0LZog8NY@GxaUC1XNYf "C (gcc) – TIO Nexus")
[Answer]
# Cubix, ~~24~~ 19 bytes
```
)uO)ABq-!wpUp)W.@;;
```
# Note
* Actually counts how many of the same characters are at the end of the input, so this works for really big integers and really long strings as well (as long as the amount of same characters at the end is smaller than the maximum precision of JavaScript (around 15 digits in base-10).
* Input goes in the input field, output is printed to the output field
[Try it here](http://ethproductions.github.io/cubix/?code=KXVPKUFCcS0hd3BVcClXLkA7Ow==&input=MTM1ODY2NjY3)
# Explanation
First, let's expand the cube
```
    ) u
    O )
A B q - ! w p U
p ) W . @ ; ; .
    . .
    . .
```
The steps in the execution can be split up in three phases:
1. Parse input
2. Compare characters
3. Print result
## Phase 1: Input
The first two characters that are executed are `A` and `B`. `A` reads all input and pushes it as character codes to the stack. Note that this is done in reverse, the first character ends up on top of the stack, the last character almost at the bottom. At the very bottom, `-1` (`EOF`) is placed, which will be used as a counter for the amount of consecutive characters at the end of the string. Since we need the top of the stack to contain the last two characters, we reverse the stack, before entering the loop. Note that the top part of the stack now looks like: `..., C[n-1], C[n], -1`.
The IP's place on the cube is where the `E` is, and it's pointing right. All instructions that have not yet been executed, were replaced by no-ops (full stops).
```
    . .
    . .
A B E . . . . .
. . . . . . . .
    . .
    . .
```
## Phase 2: Character comparison
The stack is `..., C[a-1], C[a], counter`, where `counter` is the counter to increment when the two characters to check (`C[a]` and `C[a-1]`) are equal. The IP first enters this loop at the `S` character, moving right. The `E` character is the position where the IP will end up (pointing right) when `C[a]` and `C[a-1]` do not have the same value, which means that subtracting `C[a]` from `C[a-1]` does not yield `0`, in which case the instruction following the `!` will be skipped (which is a `w`).
```
    . .
    . .
. S q - ! w E .
p ) W . . ; ; .
    . .
    . .
```
Here are the instructions that are executed during a full loop:
```
q-!;;p) # Explanation
q       # Push counter to the bottom of the stack
        #     Stack (counter, ..., C[a-1], C[a])
 -      # Subtract C[a] from C[a-1], which is 0 if both are equal
        #     Stack (counter, ..., C[a-1], C[a], C[a-1]-C[a])
  !     # Leave the loop if C[a-1]-C[a] does not equal 0
   ;;   # Remove result of subtraction and C[a] from stack
        #     Stack (counter, ..., C[a-1])
     p  # Move the bottom of the stack to the top
        #     Stack (..., C[a-1], counter)
      ) # Increment the counter
        #     Stack (..., C[a-1], counter + 1)
```
And then it loops around.
## Phase 3: Print result
Since we left the loop early, the stack looks like this: `counter, ..., C[a-1]-C[a]`. It's easy to print the counter, but we have to increment the counter once because we didn't do it in the last iteration of the loop, and once more because we started counting at `-1` instead of `0`. The path on the cube looks like this, starting at `S`, pointing right. The two no-ops that are executed by the IP are replaced by arrows that point in the direction of the IP.
```
    ) u
    O )
. B . . . S p U
. ) . . @ . . .
    > >
    . .
```
The instructions are executed in the following order. Note that the `B)` instructions at the end change the stack, but don't affect the program, since we are about to terminate it, and we do not use the stack anymore.
```
p))OB)@ # Explanation
p       # Pull the counter to the top
        #     Stack: (..., counter)
 ))     # Add two
        #     Stack: (..., counter + 2)
   O    # Output as number
    B)  # Reverse the stack and increment the top
      @ # End the program
```
[Answer]
## Python 2, 51 bytes
Takes integer as input. [Try it online](https://tio.run/nexus/python2#y7GN@Z@TmJuUkqgQbBVdYWubEJwQrWsYm5ZfpFChkJkH4lpZAQW01evUY/Uy81JSKzQMNP8XFGXmlSjkaBgaGWtyIXGMkbggzn8A)
```
lambda S:[x==`S`[-1]for x in`S`[::-1]+'~'].index(0)
```
48 bytes for string as input. [Try it online](https://tio.run/nexus/python2#y7GN@Z@TmJuUkqgQbBVdYWsbHK1rGJuWX6RQoZCZpxAcbWUF5GurG6jH6mXmpaRWaBho/i8oyswrUcjRUDc0MlbX5ELmGqMIgLn/AQ)
```
lambda S:[x==S[-1]for x in S[::-1]+'~'].index(0)
```
[Answer]
## [C#](http://csharppad.com/gist/fc79ad57ba18c5c26e3ba6f50965bca5), ~~63~~ 62 bytes
---
**Golfed**
```
i=>{int a=i.Length-1,b=a;while(a-->0&&i[a]==i[b]);return b-a;}
```
---
**Ungolfed**
```
i => {
    int a = i.Length - 1,
        b = a;
    while( a-- > 0 && i[ a ] == i[ b ] );
    return b - a;
}
```
---
**Ungolfed readable**
```
i => {
    int a = i.Length - 1, // Store the length of the input
        b = a ;           // Get the position of the last char
    // Cycle through the string from the right to the left
    //   while the current char is equal to the last char
    while( a-- > 0 && i[ a ] == i[ b ] );
    // Return the difference between the last position
    //   and the last occurrence of the same char
    return b - a;
}
```
---
**Full code**
```
using System;
namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, Int32> f = i => {
            int a = i.Length - 1, b = a;
            while( a-- > 0 && i[ a ] == i[ b ] );
            return b - a;
         };
         List<String>
            testCases = new List<String>() {
               "14892093",
               "12344444",
               "112311",
               "888888",
               "135866667"
            };
         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput: {f( testCase )}\n" );
         }
         Console.ReadLine();
      }
   }
}
```
---
**Releases**
* **v1.1** - `- 1 byte` - Thanks to [Kevin's](https://codegolf.stackexchange.com/questions/114146/get-your-dubs-together/114188#comment278413_114188) comment.
* **v1.0** - `63 bytes` - Initial solution.
---
**Notes**
Nothing to add
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), ~~6~~ 5 bytes
*1 byte saved thanks to @Luis*
```
&Y'O)
```
Try it at [**MATL Online**](https://matl.io/?code=%26Y%27O%29&inputs=%2712344444%27&version=19.8.0)
**Explanation**
```
        % Implicitly grab input as a string
&Y'     % Perform run-length encoding on the string but keep only the second output
        % Which is the number of successive times an element appeared
O)      % Grab the last element from this array
        % Implicitly display
```
[Answer]
## Batch, 91 bytes
```
@set s=-%1
@set n=1
:l
@if %s:~-2,1%==%s:~-1% set s=%s:~,-1%&set/an+=1&goto l
@echo %n%
```
The `-` prevents the test from running off the start of the string.
[Answer]
# Powershell, 41 Bytes
```
for($n="$args";$n[-1]-eq$n[-++$a]){};$a-1
```
straightforward loop backwards until a char doesn't match the last char in the string, return the index of that char -1.
-3 thanks to @AdmBorkBork - using a for loop instead of a while.
[Answer]
# JavaScript (ES6), 34 bytes
```
f=(n,p)=>n%10-p?0:1+f(n/10|0,n%10)
```
Not shorter than the regex solution.
Recursive function which evaluates the digits from right-to-left, stopping when a different digit is encountered. The result is the number of iterations. `p` is `undefined` on the first iteration, which means `n%10-p` returns `NaN` (falsy). After that, `p` equals the previous digit with `n%10`. When the current digit (`n%10`) and the previous (`p`) are different, the loop ends.
[Answer]
# [Röda](https://github.com/fergusq/roda), 12 bytes
```
{count|tail}
```
[Try it online!](https://tio.run/nexus/roda#RYvBDoIwDIbP61M0PUGi0TLUccAnISELbAmJbgbmCfDV5/Ag36Hp/3/tUw8OZxC2buLc@bcLS9DDY43C@hGDmULb6clg70GIPX5qpMbRAYlSn/3FiSjHBW22zdc4uLC7dIzHO6anNgfRe2dgjVyqqjhXEriQ5QZw2phB/QCWF3VN3L4 "Röda – TIO Nexus")
This is an anonymous function that expects that each character of the input string is pushed to the stream (I think this is valid in spirit of [a recent meta question](https://codegolf.meta.stackexchange.com/questions/11871/when-to-allow-flexible-input-output)).
It uses two builtins: `count` and `tail`:
1. `count` reads values from the stream and pushes the number of consecutive elements to the stream.
2. `tail` returns the last value in the stream.
[Answer]
## T-SQL, 238 214 Bytes
```
declare @ varchar(max) = '' declare @i int=0, @e int=0, @n int=right(@,1), @m int while (@i<=len(@)) begin set @m=(substring(@,len(@)-@i,1)) if (@n=@m) set @e=@e+1 else if (@i=0) set @e=1 set @i=@i+1 end select @e
```
Or:
```
declare @ varchar(max) = '12345678999999'
declare 
    @i int = 0,
    @e int = 0,
    @n int = right(@,1),
    @m int
while (@i <= len(@))
begin
    set @m = (substring(@,len(@)-@i,1))
    if (@n = @m) set @e = @e + 1
    else
    if (@i) = 0 set @e = 1
    set @i = @i + 1
end
select @e
```
[Answer]
# Java 7, 78 bytes
```
int c(int n){return(""+n).length()-(""+n).replaceAll("(.)\\1*$","").length();}
```
[Try it here.](https://tio.run/nexus/java-openjdk#fY1LDoIwEED3nGLSuGj9NPJRIaw8gCuW4qLWBpuUQspgYghnR1ASd7zFJJN5eSONaBq4dB5AgwK1hEFbBEmnaVnnFLbOUkI2lnGjbIFPynbz7lRthFRnYyihnOW5v16RLSF/M@0HgLq9mzE891@VfkAptKUZOm2L602w6T1A9m5QlbxqkdfjBY2lkvpRnAT7JGQsXZCCMJpYlkbL9xeV@MtyJTzEx5HTz@q9fvgA)
I tried some things using recursion or a loop, but both ended up above 100 bytes..
[Answer]
## Mathematica, ~~33~~ 30 bytes
*Thanks to Greg Martin for saving 3 bytes.*
```
Tr[1^Last@Split@Characters@#]&
```
Takes input as a string.
Gets the decimal digits (in the form of characters), splits them into runs of identical elements, gets the last run and computes the length with the standard trick of taking the sum of the vector `1^list`.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + Unix utilities, 34 bytes
```
sed s/.*[^${1: -1}].//<<<x$1|wc -c
```
[Try it online!](https://tio.run/nexus/bash#@1@cmqJQrK@nFR2nUm1opaBrWBurp69vY2NToWJYU56soJv8//9/YzAAAA "Bash – TIO Nexus")
[Answer]
# [C (clang)](http://clang.llvm.org/), 41 bytes
```
f(x){return x&&x%10-x/10%10?1:f(x/10)+1;}
```
There are already 2 other C solutions, but they both depend on loops. This uses recursion. If the last 2 digits are different then it's 1, otherwise you do 1+ the number of consecutive digits of the number with the last digit removed.
[Try it online!](https://tio.run/nexus/c-clang#@5@mUaFZXZRaUlqUp1ChplahamigW6FvaACk7Q2tgLJAtqa2oXXtf@XMvOSc0pRUm@KSlMx8vQw7rsy8EoXcxMw8Dc1qLs6CIiA3TUNJNSUmT0knTcPQxMLSyMDSWFPTGoukkbEJCGCXBMoaGmKVsgAD7LqMTS3MgMAcLAv1kYE1V@1/AA "C (clang) – TIO Nexus")
[Answer]
# JavaScript (ES6), ~~39~~ ~~38~~ ~~37~~ 27 bytes
```
f=n=>n%100%11?1:1+f(n/10|0)
```
Maybe not shorter than the regex-based solution, but I couldn't resist writing a solution entirely based on arithmetic. The technique is to repeatedly take `n % 100 % 11` and divide by 10 until the result is non-zero, then count the iterations. This works because if the last two digits are the same, `n % 100 % 11` will be `0`.
[Answer]
# [Haskell](https://www.haskell.org/), 33 bytes
```
f(h:t)=sum[1|all(==h)t]+f t
f _=0
```
[Try it online!](https://tio.run/nexus/haskell#@5@mkWFVomlbXJobbViTmJOjYWuboVkSq52mUMKVphBva/A/R8FWIdrQxMLSyMDSWEfB0MjYBASALCDT0FBHwQIMgHxjUwszIDCP5cpNzMwDastNLPBVKCjKzCtRUAFxFNKgdHFGfrlCzn8A "Haskell – TIO Nexus")
Takes string input. Repeatedly cuts off the first character, and adds 1 if all characters in the suffix are equal to the first one.
[Answer]
# R, 35 bytes
```
rle(rev(charToRaw(scan(,''))))$l[1]
```
Brief explanation
```
                  scan(,'')         # get input as a string
        charToRaw(         )        # convert to a vector of raws (splits the string)
    rev(                    )       # reverse the vector
rle(                         )$l[1] # the first length from run length encoding
```
[Answer]
# [Befunge-98](https://github.com/catseye/FBBI), 19 bytes
```
01g3j@.$~:01p-!j$1+
```
[Try it online!](https://tio.run/nexus/befunge-98#@29gmG6c5aCnUmdlYFigq5ilYqj9/7@hiYWlkYGlMRD8BwA "Befunge-98 – TIO Nexus")
This could be made shorter if I managed to only use the stack.
How it works:
```
01g3j@.$~:01p-!j$1+
01g                 ; Get the stored value (default: 32)                 ;
   3j               ; Skip to the ~                                      ;
        ~           ; Get the next character of input                    ;
         :01p       ; Overwrite the stored value with the new char       ;
             -!     ; Compare the old value and the new                  ;
               j$   ; Skip the $ when equal, else pop the counter        ;
                 1+ ; Increment the counter                              ;
; When the input runs out, ~ reflects the IP and we run: ;
   @.$
     $              ; Pop the extraneous value (the stored value) ;
   @.               ; Print the number and exit                   ;
```
]