g | x | w | all
Bytes Lang Time Link
340Rust250307T221940Zjan
009APLNARS250308T153236ZRosario
117Go250306T154826Zbigyihsu
029AWK250306T151114Zxrs
004Uiua250112T004900ZjanMakos
036Lua230621T025343Zbluswimm
018Raku230620T160234ZSean
001Thunno 2 tL230620T152529ZThe Thon
005MATL170328T133048ZSuever
002Vyxal201119T040050Zlyxal
044AWK201226T213118ZPedro Ma
038ARM Thumb2 no divide instruction/libgcc201225T000702ZEasyasPi
003Jelly201223T134000Zcaird co
012K oK201103T193133Zcoltim
024x86_64 machine code201223T015838Zengineer
004Stax201119T034310ZRazetime
019Cubix170328T141015ZLuke
009APL Dyalog Extended201103T125452Zrak1507
006Japt201103T120118ZShaggy
016Ruby nl200219T012922ZValue In
nanx8616 machine code200218T221706Z640KB
004Pyth200218T190751ZCitty
00305AB1E200218T150616ZKevin Cr
044Python 3 50170328T135531ZMr. Xcod
072Common Lisp170331T183224Zdjeis
014J170331T150137ZkaoD
039Vim170331T144431Zpacholik
004Jelly170330T230749ZATaco
036Haskell170328T231134ZGeneric
048Clojure170331T005536Zzelcon
062Java 7170330T174108Zpeech
045Befunge93170330T194451Zuser5585
040PHP170328T095008ZChristop
019Befunge98170329T223331ZJustin
035R170329T194823ZMickyT
049C#170329T082733ZDaniel D
040PHP 40chars170329T074149ZJackal
029C gcc170328T192538ZDennis
032Python 2170328T181517ZDennis
033Haskell170329T030257Zxnor
023Japt170328T213357ZOliver
027JavaScript ES6170328T133735ZETHprodu
053JavaScript ES6170328T200253ZHuntro
041C clang170328T183731ZBijan
034Bash + Unix utilities170328T181322ZMitchell
030Mathematica170328T091514ZMartin E
030Javascript ES6170328T100018ZWeedoze
214TSQL170328T142937ZNelson
022Ruby170328T133412Zm-chrzan
030Octave170328T141143ZLuis Men
012Röda170328T140645Zfergusq
034JavaScript ES6170328T140246Zuser8165
041Powershell170328T124146Zcolsw
nan170328T124034Zauhmaan
041Python 2170328T114009ZRod
078Java 7170328T121049ZKevin Cr
091Batch170328T120603ZNeil
050REXX170328T120003Zidrougge
047C170328T090721Zbetseg
051Python 2170328T091047ZDead Pos
029Mathematica170328T094210ZMartin E
004Brachylog170328T094714ZFatalize
022Perl 5170328T091125ZDada
005Jelly170328T091143ZEmigna
055C170328T090829ZSteadybo
007CJam170328T090412ZMartin E
00405AB1E170328T090229ZEmigna
009Retina170328T090159ZMartin E

Rust, 340 bytes

use{io::*,std::*};fn
main(){let mut x=net::TcpListener::bind("[::1]:8080").unwrap().accept().unwrap().0;let(mut s@mut c,mut i)=(0,(&mut x).bytes());for
b in b"GET / "{loop{let n=i.next().unwrap().unwrap();if
n!=*b{if
s!=n{s=n;c=1}else{c+=1}}else{break}}};write!(&mut x,"HTTP/1.1 200{}Type:text/plain{0}Length:{}

{}","
Content-",1+c/10,c);}

This answer's purpose is that you can use it to GET an assessment of your dubs via HTTP. Compile and run it and make an HTTP request to [::1]:8080/number with your browser.

APL(NARS), 9 chars

≢↑⌽⊂⍨⍎¨⍕⎕

it use partition on itself for find how many element are the same in the end of the number

  ≢↑⌽⊂⍨⍎¨⍕⎕
⎕:
  123
1
  ≢↑⌽⊂⍨⍎¨⍕⎕
⎕:
  1233
2
  ≢↑⌽⊂⍨⍎¨⍕⎕
⎕:
  1233333333
8
  ≢↑⌽⊂⍨⍎¨⍕⎕
⎕:
  1
1

Go, 117 bytes

import."fmt"
func f(n int)int{s:=Sprint(n)
L:=len(s)-1
c,o:=s[L],0
for i:=L;i>=0;i--{if s[i]!=c{break}
o++}
return o}

Attempt This Online!

Explanation

import."fmt"      // boilerplate
func f(n int)int{
s:=Sprint(n)      // convert n to a string
L:=len(s)-1       // start at the end of the string
c,o:=s[L],0
for i:=L;i>=0;i--{// for each char, starting from the end of the string...
if s[i]!=c{break} // if it doesn't match the last char, exit
o++}              // otherwise increment
return o}         // return the count

AWK, 29 bytes

{x=NF;gsub($NF"+$",X)}$0=x-NF

Attempt This Online!

{x=NF;           # total number of digits/chars
gsub($NF"+$",X)  # delete instances of last digit at end of line
}$0=x-NF         # print before/after difference

Uiua, 4 bytes

𝄐⊣°▽

Takes the input as a string of digits, or alternatively as an array of digits.

Explanation

  1. °▽ is run-length encoding, putting the runs first
  2. (last) gets the last run
  3. 𝄐 deletes the digits

Lua, 36 bytes

s=...print(#s:match(~~(s%10)..'+$'))

Try it online!

Raku, 18 bytes

{m/(.)$0*$/.chars}

Try it online!

m/(.)$0*$/ applies a regex to the input argument that matches any number of the same trailing characters. (In Raku, applying a regex to a number implicitly matches against its string representation.) Then .chars counts how many characters there are in the match.

Thunno 2 tL, 1 byte

ġ

Attempt This Online!

Thunno 2, 3 bytes

ġtl

Attempt This Online!

Explanation

     # Implicit input
ġ    # Group consecutive digits together
 t   # Get the last item (also done by t flag)
  l  # And push the length (also done by L flag)
     # Implicit output

MATL, 6 5 bytes

1 byte saved thanks to @Luis

&Y'O)

Try it at MATL Online

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

Vyxal, l, 2 bytes

Ġt

Try it Online!

need to get this to 2 bytes somehow – Razetime

Explained

Ġt
Ġ    # Group the integer into consecutive chunks
 t   # Take the tail of that list
     # The `-l` flag prints the length of TOS

AWK, 44 bytes

{for(d=$1%10;$1%10~d;k++)$1=($1-d)/10;$1=k}1

This piece of code uses math, so should work only with numbers.

{
for(             # $1 is the input, but will be modified during the code.
    d=$1%10;     # before the loop, records the last digit of $1 to _d_,
    $1%10~d;     # and stops if the last digit of $1 is different from _d_.
    k++          # increments 1 to _k_ after each loop.
   )
   $1=($1-d)/10; # removes the last digit of $1 and divides by 10.
                 # this uses less bytes than int($1/10).

$1=k             # after the end of the looping, assigns the count variable _k_
                 # to $1, which will become the output.
}
1                # prints $1

Try it online!


AWK, 44 bytes

{for(i=n=split($1,a,e);a[i--]~a[n];)$1=n-i}1

This code treats the input as string. Works with all kinds of characters.

{
for(
    i=n=split($1,a,e); # splits the input to the _a_ array,
                       # using the _e_ empty variable as flag (i.e, a null character)
                       # also sets the number of elements of the array
                       # to the _i_ and _n_ variables

    a[i--]~a[n];       # loops while the _i_ and _n_ elements are equal
                       # this also decrements _i_ by 1 after the evaluation
   )
     $1=n-i            # during each loop, sets the output to n-i
}
1                      # prints $1

Try it online!

ARM Thumb-2 (no divide instruction/libgcc), 38 bytes

Raw machine code:

b530 2400 250a 3401 2200 280a d302 3201
380a e7fa 0001 0010 2d0a bf08 460d 428d
d0f1 1e60 bd30

Uncommented asm:

        .text
        .arch armv6t2
        .globl dubs
        .thumb
        .thumb_func
dubs:
        push    {r4, r5, lr}
        movs    r4, #0
        movs    r5, #10
.Lloop:
        adds    r4, #1
        movs    r2, #0
.Ldivloop:
        cmp     r0, #10
        blo     .Ldivloop_end
        adds    r2, #1
        subs    r0, #10
        b       .Ldivloop
.Ldivloop_end:
        movs    r1, r0
        movs    r0, r2
        cmp     r5, #10
        it      eq
        moveq   r5, r1
        cmp     r5, r1
        beq     .Lloop
        subs    r0, r4, #1
        pop     {r4, r5, pc}

Explanation

C function signature:

// Assume: post_id != 0
uint32_t dubs(uint32_t post_id);

First, push registers and set up our dubs counter in r4:

dubs:
        push    {r4, r5, lr}
        movs    r4, #0

Now, in order to reuse the loop, we use a "magic" value of 10 for the last digit in r5, and set it at the end of the loop.

        movs    r5, #10

Begin the count by incrementing the dubs counter:

.Lloop:
        adds    r4, #1

Now, we start our divmod loop to divide the ID by 10 and get the remainder.

The divided ID will be in r2 and the remainder will be in r0.

        movs    r2, #0
.Ldivloop:
        cmp     r0, #10
        blo     .Ldivloop_end
        adds    r2, #1
        subs    r0, #10
        b       .Ldivloop

That is basically this in C:

uint32_t quotient = 0;
while (dividend >= 10) {
    ++quotient;
    dividend -= 10;
}
uint32_t remainder = dividend;

This could probably be optimized. We ended up with the registers in the wrong spot, so we have to move things around. Specifically, we want the remainder in r1 and the divided ID in r0.

The biggest problem is dealing with movs either clobbering the flags or requiring hi registers. If it didn't do that, I would put it after the cmp.

.Ldivloop_end:
        movs    r1, r0
        movs    r0, r2

Now, we check for that magic number and set the lowest digit to that.

        cmp     r5, #10
        it      eq
        moveq   r5, r1

Now, check if the new remainder in r1 and loop if it is the same as the last digit.

        cmp     r5, r1
        beq     .Lloop

Move the dubs count into the return register and return. We are actually one too high so we have to correct it.

        subs    r0, r4, #1
        pop     {r4, r5, pc}

Jelly, 3 bytes

ŒɠṪ

Try it online!

Well, there’s a 5 byte and a 4 byte Jelly answer, so might as well go for 3 bytes

How it works

ŒɠṪ - Main link. Takes l on the left as a list of digits
Œɠ  - Group adjacent equal values in l and get the lengths of each
  Ṫ - Get the last one

K (oK), 15 12 bytes

{+/&\|x=*|x}

Try it online!

Takes input as a string.

x86_64 machine code, 24 bytes

Could probably be golfed a bit further.

Input and output is through rax as integers.

00000000  6a 0a 5d 31 f6 31 d2 f7  f5 89 d3 ff c6 31 d2 f7  |j.]1.1.......1..|
00000010  f5 39 d3 74 f6 89 f0 c3                           |.9.t....|

Disassembly (with explanation):

dubs:
  6a 0a                 push   0xa
  5d                    pop    rbp      ; set rbp to 10 (for divison)
  31 f6                 xor    esi,esi  ; zero counter
  31 d2                 xor    edx,edx  ; zero upper dividend
  f7 f5                 div    ebp      ; initial divide (can this be golfed into the other divide?)
  89 d3                 mov    ebx,edx  ; set ebx (repeating digit)
loop:
  ff c6                 inc    esi      ; inc counter
  31 d2                 xor    edx,edx  ; zero upper dividend (gets filled with remainder)
  f7 f5                 div    ebp      ; divide
  39 d3                 cmp    ebx,edx  ; compare repeating digit with digit 'popped'
  74 f6                 jz     loop     ; if equal keep looping
  89 f0                 mov    eax,esi  ; move counter to eax for output
  c3                    ret

Full program source to run subroutine:

; nasm -felf64 -odubs.o dubs.asm
; ld -odubs dubs.o
; ./dubs; echo $?

bits 64

section .text
    global _start

_start:
    mov rax, 12344444
    call dubs
    
    mov rdi, rax
    mov rax, 60
    syscall ; exit with return val as exit code
    
dubs:
    push 10
    pop rbp
    xor esi, esi
    xor edx, edx
    div ebp ; eax quot edx rem
    mov ebx, edx
loop:
    inc esi
    xor edx, edx
    div ebp ; eax quot edx rem
    cmp ebx, edx
    jz loop
    mov eax, esi
    ret

Stax, 4 bytes

E:GH

Run and debug it

Cubix, 24 19 bytes

)uO)ABq-!wpUp)W.@;;

Note

Try it here

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

APL (Dyalog Extended), 9 bytes

⊃⍸⌽1,2≠/⍞

input as a string

1,2≠/ 1 concatenated with n-wise reduction with ≠, boolean mask of the starts of sections

reverse

⊃⍸ index of the first 1

Try it online!

Japt, 6 bytes

ì òÎÌÊ

Try it or run all test cases

ì òÎÌÊ     :Implicit input of integer
ì          :To digit array
  ò        :Partition between truthy pairs
   Î       :   Sign of difference
    Ì      :Last element
     Ê     :Length

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!

x86-16 machine code, IBM PC DOS, 22 21 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:

enter image description here

Pyth, 4 bytes

her9

Kinda surprised this hasn't been posted yet.

Try it online!

05AB1E, 3 bytes

Åγθ

Try it online or verify all test cases.

Or alternatively:

γθg

Try it online or verify all test cases.

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)

Python 3 - 50 44 bytes

Full program (in Python 3, input() returns a string, no matter the input):

g=input();print(len(g)-len(g.rstrip(g[-1]))) 

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.

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:

Vim - 39

ix^[Y$d?[^^R=@@[len(@@)-2]^M]^Mcc^R=len(@2)^M

(^[, ^Ms and ^Rs are one char each)

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.

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

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))

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

Befunge-93, 45 bytes

<_v#`0:~
pv>$00p110
p>00g-#v_10g1+10
  @.g01<

Try it online!

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.

Befunge-98, 19 bytes

01g3j@.$~:01p-!j$1+

Try it online!

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                   ;

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

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"));
          Console.ReadLine();
      }
  }

PHP 40chars

(Does not take into account php tags)

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

C (gcc), 32 29 bytes

f(x){x=x%100%11?1:-~f(x/10);}

This is a port of my Python answer.

This work with gcc, but the lack of a return statement is undefined behavior.

Try it online!

Python 2, 38 32 bytes

f=lambda n:0<n%100%11or-~f(n/10)

Thanks to @xnor for saving 6 bytes!

Try it online!

Haskell, 33 bytes

f(h:t)=sum[1|all(==h)t]+f t
f _=0

Try it online!

Takes string input. Repeatedly cuts off the first character, and adds 1 if all characters in the suffix are equal to the first one.

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

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.

JavaScript (ES6), 53 bytes

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

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!

Bash + Unix utilities, 34 bytes

sed s/.*[^${1: -1}].//<<<x$1|wc -c

Try it online!

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.

Javascript (ES6), 55 52 32 30 bytes

a=>a.match`(.)\\1*$`[0].length

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

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

Ruby, 28 22 bytes

->s{s[/(.)\1*$/].size}

Anonymous function that takes the number as a string.

Octave, 30 bytes

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

Try it online!

Röda, 12 bytes

{count|tail}

Try it online!

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).

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.

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.

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.

C#, 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


Notes

Nothing to add

Python 2, 47 41 bytes

lambda s:len(`s`)-len(`s`.rstrip(`s%10`))

Try it online!

36 bytes - For a more flexible input

lambda s:len(s)-len(s.rstrip(s[-1]))

Try it online!

Java 7, 78 bytes

int c(int n){return(""+n).length()-(""+n).replaceAll("(.)\\1*$","").length();}

Try it here.

I tried some things using recursion or a loop, but both ended up above 100 bytes..

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.

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.

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!

Python 2, 51 bytes

Takes integer as input. Try it online

lambda S:[x==`S`[-1]for x in`S`[::-1]+'~'].index(0)

48 bytes for string as input. Try it online

lambda S:[x==S[-1]for x in S[::-1]+'~'].index(0)

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.

Brachylog, 4 bytes

ẹḅtl

Try it online!

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.

Perl 5, 22 bytes

21 bytes of code + -p flag.

/(.)\1*$/;$_=length$&

Try it online!

/(.)\1*$/ gets the last identical numbers, and then $_=length$& assigns its length to $_, which is implicitly printed thanks to -p flag.

Jelly, 5 bytes

DŒgṪL

Try it online!

Explanation

D      # convert from integer to decimal   
 Œg    # group runs of equal elements
   Ṫ   # tail
    L  # length

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!

CJam, 7 bytes

re`W=0=

Try it online!

Explanation

r   e# Read input.
e`  e# Run-length encode.
W=  e# Get last run.
0=  e# Get length.

05AB1E, 4 bytes

.¡¤g

Try it online! or as a Test suite

Explanation

.¡    # group consecutive equal elements in input
  ¤   # get the last group
   g  # push its length

Retina, 9 bytes

&`(.)\1*$

Try it online!

Counts the number of overlapping matches of (.)\1*$ which is a regex that matches a suffix of identical characters.