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

• Are we allowed to take input as string? – Dead Possum Mar 28 '17 at 9:11
• @DeadPossum I would assume that's allowed, since you get a string anyway if you read the input from STDIN, command-line argument or file (which are all admissible input methods). – Martin Ender Mar 28 '17 at 9:19
• Can we assume that the input will be greater than 0? – Martin Ender Mar 28 '17 at 10:01
• @MartinEnder Yes – sagiksp Mar 28 '17 at 10:05
• Upvote for the dubs game! Check'em! – ZombieChowder Mar 28 '17 at 12:31

# C, 62 55 bytes

i,j;f(n){for(i=0,j=n%10;++i;n/=10)if(j-n%10)return--i;}


Try it online!

## REXX, 50 bytes

arg ''-1 # 1 n
say length(n)-length(strip(n,T,#))


Parse argument with empty string, causing parsing cursor to move to end of argument, then left one step, put remainder (one character) of argument in # variable, move to first character and put first word of argument in n variable.

Strip trailing characters equivalent to # from n and compare length to n.

# Octave, 30 bytes

@(s)find(flip(diff([0 +s])),1)


Try it online!

# Ruby, 28 22 bytes

->s{s[/(.)\1*$/].size}  Anonymous function that takes the number as a string. • I believe you can get the match of a regex in Ruby like s[/(.)\1*$/]. – user81655 Mar 28 '17 at 13:57

# C (clang), 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!

# JavaScript (ES6), 53 bytes

f=(n,i=1)=>(a=[...n]).pop()==a[a.length-1]?f(a,i+1):i


# Japt, 23 bytes

¬â l ¥1?Ul :Uw ¬b@X¦UgJ


Try it online!

### Explanation:

¬â l ¥1?Ul :Uw ¬b@X¦UgJ
¬                         // Split the input into an array of chars
â                        // Return all unique permutations
l ¥1                   // Check if the length is equal to 1
?                  // If yes, return:
Ul                //   The length of the input
:             // Else, return:
Uw           //   The input, reversed
¬         //   Split into an array of chars
@       //   Iterate through, where X is the iterative item
b        //   Return the first index where:
X¦     //     X !=
UgJ  //     The last char in the input


# Befunge-93, 45 bytes

<_v#0:~
pv>$00p110 p>00g-#v_10g1+10 @.g01<  Try it online! # Clojure, 48 bytes #(-> (partition-by identity (str %)) last count) Usage: (#(-> (partition-by identity (str %)) last count) 123455) => 2 Ungolfed: (defn count-digits [n] (-> (partition-by identity (str n)) last count))  # Common Lisp, 82 bytes (defun c (n) (if (eq (mod n 10) (floor (mod n 100) 10)) (+ 1 (c (floor n 10))) 1)) Ungolfed: (defun c (n) (if (eq (mod n 10) (floor (mod n 100) 10)) (+ 1 (c (floor n 10))) 1))  • Welcome To PPCG! Wonderful first post, It looks like you have the basics of formatting down, just note that in the future you an make multiple answers if you use multiple languages (good for getting more rep :) ) – Taylor Scott Mar 31 '17 at 1:50 # Haskell, 36 bytes ## Without import solution (39 bytes) f n=length.takeWhile(==last n)$reverse n


Note that a pointfree solution is longer (and less understandable): EDIT: since anonymous functions are allowed, let's shave off two bytes which brings us to 39 (still longer than 36):

(length.).takeWhile.(==).last<*>reverse


## With import solution (36 bytes, 19 without import)

import Data.List
f=length.last.group


Run like f "2394398222222" either way

# Jelly, 4 bytes

ŒrṪṪ


Takes input as a string, returns a number.

Try it online!

Relatively simply, Œr Run-length encodes the input, Ṫ pushes the last pair, then Ṫ pushes its second item. Which thus gives us the length of consecutive digits at the end of the string.

# PHP 40chars

(Does not take into account php tags)

strlen(preg_match('/(.)\1*$/',$argv))

• I think you mean preg_match('/(.)\1*$/',$argv,$t);echo strlen($t); or as alternative <?=strlen(preg_filter('/.*?((.)\2*)$/','\1',$argv)); – Jörg Hülsermann Mar 31 '17 at 2:08

# C#, 49 bytes

i=>i.Reverse().TakeWhile(x=>x==i.Last()).Count();


Try it here

Full code

  using System;
using System.Linq;

class Program
{
static void Main()
{
Func<string, int> func = i=>i.Reverse().TakeWhile(x=>x==i.Last()).Count();

Console.WriteLine(func("14892093"));
Console.WriteLine(func("12344444"));
Console.WriteLine(func("112311"));
Console.WriteLine(func("888888"));
Console.WriteLine(func("135866667"));
}
}


# Java 7, 64 62 bytes

Golfed:

int w(int x){int r=1,d=x%10;while((x/=10)%10==d)r++;return r;}


Ungolfed:

int w(int x)
{
int r = 1, d = x % 10;
while ((x /= 10) % 10 == d)
r++;
return r;
}


Try it online

# Vim - 39

ix^[Y$d?[^^R=@@[len(@@)-2]^M]^Mcc^R=len(@2)^M  (^[, ^Ms and ^Rs are one char each) • insert non-number (for 88888 input), copy line, move to the end • delete searching backwards for a char other then the last char • replace line with length of deleted text # J, 14 bytes >:i.&1}.~:|.":  Try it online! It's fortunate that the challenge allows a REPL command. As a verb (function) it's 20 bytes: 3 :'>:i.&1}.~:|.":y'  For arbitrarily large integers, the literal must be suffixed by x. ### Explained Applied right to left, all monadic verbs: • ": Format - Stringifies its argument • |. Reverse • ~: Nub sieve - Produces a boolean array of 1's each time a new item is introduced, 0 otherwise • }. Behead - Removes first item of array • i.&1 Index of - Gets index of first 1. i. is actually a dyadic verb, but &1 ties right argument to 1. • >: Increment # Common Lisp, 72 chars (lambda(i)(do((n i(floor n 10))(c 1(1+ c)))((/= 0(mod(mod n 100)11))c)))  Unoglfed (lambda (i) (do ((n i (floor n 10)) (c 1 (1+ c))) ((/= 0 (mod (mod n 100) 11)) c)))  Explanation (/= 0 (mod (mod n 100) 11)) This checks to see if the last two digits of n are different- if n%100 is not divisible by 11. (do ((n i (floor n 10)) (c 1 (1+ c))) (... c))  do is a powerful generic looping construct in lisp. Its first argument is a list describing the looping variables. Each element is a list of (variable initial-value step-form) where step-form is evaluated each time through the loop to update that variable. The second argument is a test to perform to end the loop (the test I covered above) and a list of values to return after looping (in this case just c, which has been incrementing each time though the loop). (lambda (i) ...) Wraps the operation in an anonymous function that takes the number as an integer. # 05AB1E, 3 bytes Åγθ  Or alternatively: γθg  Explanation: Åγ # Run-length decode the (implicit) input-integer # i.e. 1333822 → [1,3,1,2] θ # Pop and push the last item # → 2 # (which is output implicitly as result) γ # Split the (implicit) input-integer into parts of subsequent equal digits # i.e. 1333822 → [1,333,8,22] θ # Pop and push the last item # → 22 g # Pop and push its length # → 2 # (which is output implicitly as result)  # Pyth, 4 bytes her9  Kinda surprised this hasn't been posted yet. Try it online! # x86-16 machine code, IBM PC DOS, 2221 20 bytes Binary: 00000000: d1ee 8a1c 8d38 8a05 fdf3 aef6 d191 052f .....8........./ 00000010: 0ecd 10c3 ....  Build and test DUBS.COM with xxd -R. Unassembled listing: D1 EE SHR SI, 1 ; SI to command line tail (80H) 8A 1C MOV BL, BYTE PTR[SI] ; BX = input string length 8D 38 LEA DI, [BX][SI] ; DI to end of string 8A 05 MOV AL, BYTE PTR[DI] ; AL = last char FD STD ; set LODS to decrement F3 AE REPZ SCASB ; scan [DI] backwards until AL doesn't match F6 D1 NOT CL ; negate CL to get number of matches + 1 91 XCHG AX, CX ; AL = CL 05 2F0E ADD AX, 0E2FH ; ASCII convert and adjust, BIOS tty function CD 10 INT 10H ; write number to console C3 RET ; return to DOS  A standalone PC DOS executable program. Input via command line, output number to console. Notes: This takes advantage of a few "features" of PC DOS register startup values; specifically BH = 0, CX = 00FFH and SI = 100H. REPZ decrements CX on every compare operation, so starting at 00FFH will yield a negative count of reps. It is off-by-one because REPZ decrements before comparison, so the first non-match still gets counted. That number is ones-complimented and adjusted by 1 to get the count of matched digits. Also, since CH = 0 it's possible to combine ADD AL, '0'-1 and MOV AH, 0EH into a single instruction ADD AX, 0E2FH to save 1 byte, since AH will be 0. Old-school SIMD for you! I/O: # Ruby-nl, 16 bytes Input is STDIN. Subtracts the position of the start of the dubs sequence from the length of the string (technically, the position of the end of the string). p~/$/-~/(.)\1*\$/
`

Try it online!