g | x | w | all
Bytes Lang Time Link
007K ngn/k210423T215735Zcoltim
008Uiua240827T104126Znyxbird
004Nekomata240827T014901Zalephalp
026Juby240827T001816ZJordan
058Factor220527T121623Zchunes
011Pyth220307T152622Zsinvec
008Risky210615T201049Zxigoi
00505AB1E210614T084719ZKevin Cr
052Excel210426T123922ZAxuary
029C# Visual C# Interactive Compiler210426T104456Zbaltermi
009Pari/GP210426T022849ZJoe Slat
027Ruby210426T061441ZG B
040Hy210425T202540Zadl
045Emacs Lisp210425T202439Zadl
064Desmos210425T200110ZAiden Ch
005Japt g210424T220642ZShaggy
032Haskell210424T162022ZAZTECCO
018Julia210424T142858ZMarcMush
032GAWK210424T134521ZPedro Ma
1612J210424T034954ZJonah
048Red210424T082938ZGalen Iv
027C gcc210424T002358ZNoodle9
038R210424T065720ZDominic
009Brachylog210424T041126ZUnrelate
287MMIX210424T014635ZNoLonger
040Python 3210423T214036Zknosmos
035.NET Regex210423T231013ZNeil
034Retina 0.8.2210423T225928ZNeil
008MATL210423T214857ZLuis Men
011Charcoal210423T224541ZNeil
001Vyxal210423T220716Zlyxal
022JavaScript V8210423T214306ZRydwolf
022Raku210423T215133ZSean
015Wolfram Language Mathematica210423T214453Zatt
031Python 2210423T214047Zdingledo
001Jelly210423T214001ZRydwolf

K (ngn/k), 11 8 7 bytes

*&|(\).

Try it online!

Takes input as a list of two integers, the first b, the second n, e.g. 2 512.

Uiua, 8 bytes

-1⊢⊚◿ⁿ⇡,

Try it!

-1⊢⊚◿ⁿ⇡,
      ⇡, # range up to n
    ◿ⁿ   # get b^x%m for each
  ⊢⊚     # index of the first non-zero
-1       # minus 1

Nekomata, 4 bytes

ˡ{v¦

Attempt This Online!

ˡ{v¦
ˡ{      Loop until failure and count the number of iterations
  v         Push the second input to the stack
   ¦        Divide the first input by it and check if the result is an integer

J-uby, 26 bytes

:digits|:find_index+(:<&0)

Attempt This Online!

Factor, 58 bytes

:: g ( n b -- m ) n b mod 0 > [ 0 ] [ n b / b g 1 + ] if ;

Try it online!

Pyth, 11 bytes

Mtf@_jGHtT;

Try it online!

Risky, 8 bytes

0+02?}?0?+1*?:0

Try it online!

Explanation

0        0
+      +
0        0
2    prepend to
?        first input
}      base convert
?        second input
0  reduce
?        accumulator
+      +
1        1
*    ×
?        item
:      =
0        0

This problem translates really nicely to a Risky program. I had to add only two filler characters to make the tree symmetrical.

05AB1E, 5 bytes

вRĀ1k

First input is base \$b\$, second input is \$n\$.

Try it online or verify all test cases.

Explanation:

в      # Convert the (implicit) input `n` to the (implicit) input-base `b` as list
 R     # Reverse this list
  Ā    # Truthify each value (0 remains 0; everything else becomes 1)
   1k  # And get the first (0-based) index of a 1 in this list
       # (after which this index is output implicitly as result)

Excel, 52 bytes

=LET(x,SEQUENCE(LOG(A2,B2)),MAX(x*(MOD(A2,B2^x)=0)))

My first attempt below with built-ins was limited because BASE only works up to 36. As a bonus the second attempt was shorter. Goes to show, built-ins aren't always the answer.

Initial Attempt, 70 bytes

=LET(x,BASE(A2,B2),q,SEQUENCE(LEN(x)),MAX(q*(RIGHT(x,q)=REPT("0",q))))

Using LAMBDA from Insider Beta, 41 bytes

=LAMBDA(n,b,IF(MOD(n,b)=0,f(n/b,b)+1,0))

The above is 40 bytes plus 1 byte to set it equal to f in the Name Manager.

C# (Visual C# Interactive Compiler), 29 bytes

f=(n,b)=>n=n%b>0?0:1+f(n/b,b)

Try it online!

Pari/GP, 9 bytes

valuation

Try it online!

Ruby, 27 bytes

f=->n,b{n%b>0?0:1+f[n/b,b]}

Try it online!

Hy, 40 bytes

(defn f[n b](if(% n b)0(+(f(/ n b)b)1)))

Try it online!

Emacs Lisp, 45 bytes

(defun f(n b)(if(=(% n b)0)(+(f(/ n b)b)1)0))

Try it online!

It seems that recursive functions doesn't work for Emacs Lisp on TIO.

Desmos, 64 bytes

c=[0...log_bn]
a=n/b^c
f(n,b)=max(c\left\{a=ceil(a):1,0\right\})

Try It On Desmos!

Try It On Desmos(Prettified)!

Function to test on: \$f(n,b)\$

It seems like it only works if you copy/paste one expression at a time, instead of copy/pasting it all at once.

Japt -g, 5 bytes

ìV Ôð

Try it

ìV Ôð     :Implicit input of integers U=n & V=b
ìV        :Convert U to a base-V digit array
   Ô      :Reverse
    ð     :0-based indices of truthy (non-zero) elements
          :Implicit output of first element

Haskell, 32 bytes

a?b|a`mod`b>0=0|c<-a`div`b=1+c?b

Try it online!

Julia, 18 bytes

n*b=n%b<1&&1+n/b*b

Try it online!

GAWK, 32 bytes

{for(;$1/$2^++e!~/\./;);$0=e-1}1

Strangely, does not work on TIO, and also couldn't run it in mawk.

{for(;                 starts the loop
      $1/$2^++e        divides n by b^(e), e increasing each time
               !~/\./  continue while this division does not match a dot
                       (i.e, while it's a integer)
    ;);                the semicolon after the for means "run no command while looping"
    $0=e-1             after looping, substitutes the input ($0) for e-1
}1                     shows $0

J, 16 12 bytes

[:#.~0=#.inv

Try it online!

-4 thanks to xash!

Red, 48 bytes

f: func[n b][either(n % b)> 0[0][1 + f n / b b]]

Try it online!

C (gcc), 38 27 bytes

Saved 11 bytes thanks to AZTECCO!!!

f(n,b){n=n%b?0:1+f(n/b,b);}

Try it online!

R, 38 bytes

f=function(n,b)`if`(n%%b,0,1+f(n/b,b))

Try it online!

Brachylog, 9 bytes

ḃ₎,0a₁=kl

Try it online!

  ,0         Append a 0 to
ḃ₎           the digits of n in base b.
    a₁       Find the largest suffix
      =      all elements of which are equal,
       k     remove its last element,
        l    and output its length.

The shorter ḃ₎a₁≡ᵛ⁰l cannot handle cases with no trailing zeroes, since a₁ cannot generate an empty suffix of a non-empty list, and if it could ≡ᵛ⁰ would fail on it anyhow.

Without utilizing base conversion:

Brachylog, 11 bytes

⟨{f↔∋~^}h⟩t

Try it online!

    ∋          An element
  f            of the list of factors
⟨{     } ⟩     of n
   ↔           in descending order
     ~^ h t    is b raised to the power of the output.

MMIX, 28 bytes (7 instrs)

35020001 F7010000
1E000001 E7020001
FE030006 5303FFFD
F8030000

Explanation

    NEG  $2,0,1     // set $2 to -1
    PUT  rD,0       // clear hidiv register
lop DIVU $0,$0,$1   // set $0 to $0/$1 and rR to $0%$1
    INCL $2,1       // increment $2
    GET  $3,rR      // $3 = rR
    PBZ  $3,lop     // if $3, jump back to loop
    POP  3,0        // return three registers; $2 goes into lowest slot!

The only tricks I used were to start the register at -1 to simplify the logic, and to use the properties of POP to shift the register while returning. The MMIX register shuffle is useful when golfing.

(It's possible to shave an extra tetra by using DIV instead of DIVU and omitting the PUT, but this changes the semantics to be signed instead of unsigned. For completeness, this leads to the following machine code.)

35020001 1C000001 E7020001
FE030006 5303FFFD F8030000

Python 3, 83 78 57 47 40 bytes

f=lambda n,b:1+f(n/b,b)if n>n%b<=0else 0

Finally figured out how to use a lambda to solve this

.NET Regex, 35 bytes

\G(?=1+,1(1+))(?=(1\1)+,)(?<-2>\1)+

Try it online! Test suite written using Retina. Takes n,b as input in unary as strings of 1s and outputs the result as the number of successful matches. Explanation:

\G

Each match must begin at the end of the previous match (with the first match beginning at the start of the string).

(?=1+,1(1+))

Look ahead to find b and capture b-1 as \1.

(?=(1\1)+,)

Ensure that 1\1, i.e. b, divides n.

(?<-2>\1)+

Subtract b-1 times the quotient, leaving the quotient, i.e. n/b. This value is then the input to the next match.

Retina 0.8.2, 34 bytes

\d+
$*
+%`^(1+),(\1)+$
¶$1,$#2$*
¶

Try it online! Link includes test cases. Takes input in order b,n. Explanation:

\d+
$*

Convert b and n to unary.

+%`^(1+),(\1)+$
¶$1,$#2$*

Repeatedly divide n by b.

Count the number of divisions.

MATL, 11 8 bytes

_YAPf1)q

Inputs are in reverse order.

Try it online! Or verify all test cases.

Explanation

Consider inputs n = 12321, b = 3 as an example.

_    % Implicit input: b. Negate
     % STACK: -3
YA   % Implicit input: n. Convert n to specified base. A negative base -b is
     % interpreted as digits 0,1,...,b-1, and b can be arbitrarily large.
     % (A positive base b is interpreted as chars '0','1',...,'9','A','B',...,
     % and then b cannot exceed 36)
     % STACK: [1 2 1 2 2 0 1 0 0]
P    % Flip
     % STACK: [0 0 1 0 2 2 1 2 1]
f    % Find: indices of non-zeros
     % STACK: [3 5 6 7 8 9]
1)   % First entry
     % STACK: 3
q    % Subtract 1. Implicit display
     % STACK: 2

Charcoal, 11 bytes

IL⊟⪪⭆↨NN¬ι0

Try it online! Link is to verbose version of code. Explanation:

      N     Input `n`
     ↨      Converted to base
       N    Input `b`
    ⭆       Map over elements and join
         ι  Current element
        ¬   Logical Not
   ⪪      0 Split string on literal `0`
  ⊟         Take the last string of `1`s
 L          Take the length
I           Cast to string
            Implicitly print

Vyxal, 1 byte

Ǒ

Try it Online!

laughs in stolen jelly built-ins

JavaScript (V8), 22 bytes

-3 thanks to @user

d=>g=x=>x%d?0:g(x/d)+1

Try it online!

Raku, 22 bytes

{($^n,*/$^x.../\./)-2}

Try it online!

$^n, * / $^x ... /\./ is a sequence starting with $^n (the first argument to the function), where each term is obtained by dividing the previous one by $^x (the second argument to the function), and ending when a term matches the regex /\./ (ie, a period). Subtracting 2 from this sequence treats it as a number equal to its length.

Wolfram Language (Mathematica), 15 bytes

IntegerExponent

Try it online!

Built-in.

Python 2, 31 bytes

Returns False for 0.

f=lambda n,b:n%b<1and-~f(n/b,b)

Try it online!

Jelly, 1 byte

Try it online!

Don't know Jelly