| Bytes | Lang | Time | Link |
|---|---|---|---|
| 007 | K ngn/k | 210423T215735Z | coltim |
| 008 | Uiua | 240827T104126Z | nyxbird |
| 004 | Nekomata | 240827T014901Z | alephalp |
| 026 | Juby | 240827T001816Z | Jordan |
| 058 | Factor | 220527T121623Z | chunes |
| 011 | Pyth | 220307T152622Z | sinvec |
| 008 | Risky | 210615T201049Z | xigoi |
| 005 | 05AB1E | 210614T084719Z | Kevin Cr |
| 052 | Excel | 210426T123922Z | Axuary |
| 029 | C# Visual C# Interactive Compiler | 210426T104456Z | baltermi |
| 009 | Pari/GP | 210426T022849Z | Joe Slat |
| 027 | Ruby | 210426T061441Z | G B |
| 040 | Hy | 210425T202540Z | adl |
| 045 | Emacs Lisp | 210425T202439Z | adl |
| 064 | Desmos | 210425T200110Z | Aiden Ch |
| 005 | Japt g | 210424T220642Z | Shaggy |
| 032 | Haskell | 210424T162022Z | AZTECCO |
| 018 | Julia | 210424T142858Z | MarcMush |
| 032 | GAWK | 210424T134521Z | Pedro Ma |
| 1612 | J | 210424T034954Z | Jonah |
| 048 | Red | 210424T082938Z | Galen Iv |
| 027 | C gcc | 210424T002358Z | Noodle9 |
| 038 | R | 210424T065720Z | Dominic |
| 009 | Brachylog | 210424T041126Z | Unrelate |
| 287 | MMIX | 210424T014635Z | NoLonger |
| 040 | Python 3 | 210423T214036Z | knosmos |
| 035 | .NET Regex | 210423T231013Z | Neil |
| 034 | Retina 0.8.2 | 210423T225928Z | Neil |
| 008 | MATL | 210423T214857Z | Luis Men |
| 011 | Charcoal | 210423T224541Z | Neil |
| 001 | Vyxal | 210423T220716Z | lyxal |
| 022 | JavaScript V8 | 210423T214306Z | Rydwolf |
| 022 | Raku | 210423T215133Z | Sean |
| 015 | Wolfram Language Mathematica | 210423T214453Z | att |
| 031 | Python 2 | 210423T214047Z | dingledo |
| 001 | Jelly | 210423T214001Z | Rydwolf |
K (ngn/k), 11 8 7 bytes
*&|(\).
Takes input as a list of two integers, the first b, the second n, e.g. 2 512.
(\).convertnto baseb|reverse&use monadic where, e.g. convert0 0 2into2 2*return the first value
Uiua, 8 bytes
-1⊢⊚◿ⁿ⇡,
-1⊢⊚◿ⁿ⇡,
⇡, # range up to n
◿ⁿ # get b^x%m for each
⊢⊚ # index of the first non-zero
-1 # minus 1
Nekomata, 4 bytes
ˡ{v¦
ˡ{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
Risky, 8 bytes
0+02?}?0?+1*?:0
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.
Emacs Lisp, 45 bytes
(defun f(n b)(if(=(% n b)0)(+(f(/ n b)b)1)0))
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\})
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 Ôð
ì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
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
-4 thanks to xash!
#.invConvert to list of base digits0=Converts zeroes to ones, everything else to 0.[:#.~Use that number as a mixed base to convert itself to a number -- effectively zeroes out everything to the left of the rightmost 0, summing all the ones (that were originally trailing zeroes).
Brachylog, 9 bytes
ḃ₎,0a₁=kl
,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
∋ 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
Raku, 22 bytes
{($^n,*/$^x.../\./)-2}
$^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.