Hot answers tagged

10

Pyth, \$(ω^ω, 6)\$ >_PE_P Try it online! Compares the reversed prime factorizations of the two inputs. Pyth, \$(ε_0, 17)\$ L_SmylP#U_dPb>yEy Try it online! L def y(b): Pb prime factors of b m map over d: _d -d U range [-d, …, -1] P# ...


9

///, 80 bytes /!1/1!//!/S'SS'.'//1/S.B'S.B|B'SS.B|S|.SS'B|S'SS|B.SxBxSSxBxS|B..S//B/\\//S/\//! Takes input in unary as 1s appended to the program. Produces output in unary as .s. Try it online! The program sends the ! to the end of the input, then makes several more substitutions. After completing the substitutions that exist in the initial program, each 1 ...


9

K (ngn/k), 43 41 bytes {{+/'y*/:(u*|+\|+/x*u)-x*++\u:=#x}\x:\:x} Try it online! Brutally golfed by ngn. -2 bytes because it is allowed to output starting with A itself. input: matrix A with size n * n {{...}\x:\:x} scan over the list of n copies of A {...} inner fn: x is running matrix, y is A u:=#x u: identity matrix of size n x*++...


9

Haskell, \$(\omega, 3)\$ This solution is dead simple, really can't be beat in Haskell. (<) Try it online! Haskell, \$(\omega+n,19+2\left\lfloor\log_{10}(n+1)\right\rfloor)\$ Here's a scheme to get \$\omega + n\$ for any \$n\in\mathbb{N}\$. Just replace the 9s below with one more than \$n\$. This will make the first \$n\$ numbers bigger than all other ...


7

R, 113 109 103 96 95 bytes Or R>=4.1, 88 bytes by replacing the word function with \. -4 bytes and another -7 thanks to @Dominic van Essen. function(A,B=A)for(i in 2:nrow(A))B=print((diag(sum(b<-diag(B))-cumsum(b))-B*upper.tri(B))%*%A) Try it online! Straightforward approach. The terms on the diagonal are calculated as cumsum-sum. Solution shorter ...


7

JavaScript (V8), 21 bytes b=>g=n=>n&&1+g(n/b|0) Try it online!


7

Python 2, 28 bytes f=lambda x,b:x and-~f(x/b,b) Try it online! thanks @Kevin Cruijssen for -1 byte by using python 2 instead of python 3


7

Pari/GP, 29 bytes n->!sumdiv(n,d,Str(d)>Str(n)) Try it online! Using the hint.


7

05AB1E, 5 bytes Using the hint, suggested by Kevin Cruijssen ѧ{θQ Try it online! Cast the divisors Ñ to string §, sort {, is the last one θ equal to the input Q? Or 9 bytes without the hint, -1 byte thanks to Kevin Cruijssen: ÑÂøεS∍‹}P Try it online! Ñ # divisors of the input Âø # zip with its reverse ε } # map over the divisor ...


6

Jelly, 13 12 bytes Ø.,æ*ÆḊN,ÆṭƲ Try it online! Takes input as [v, u] on the left, and a on the right. Outputs as [β, α] -1 byte thanks to ovs! Uses xnor's formula that $$\alpha = \operatorname{tr} \left( \begin{bmatrix} 0 & 1 \\ v & u \end{bmatrix}^a \right) \\ \beta = -(-v)^a = - \det \left( \begin{bmatrix} 0 & 1 \\ v & u \end{bmatrix}^a \...


6

Python 2, 182 bytes def E(a,b): if b:x,y,d=E(b,a%b);return y,x-a/b*y,d return 1,0,a def f(a,b,c,d):x,y,g=E(a,b);z,w,h=E(c,d);j=E(g,h)[2];return(b/g,-a/g,0,0),(0,0,d/h,-c/h),(-x*h/j,-y*h/j,z*g/j,w*g/j) Try it online! Yes, it is possible to solve it without fancy built-ins. And this gives relatively good results for a non-LLL one. How it works I derived a ...


6

Python 3 + numpy, 117, 99, 97, 91, 89(@Dingus), 88 bytes from numpy import* def f(M): N=M;T=triu(M==M) for _ in M:N=T@N[T&T.T,print(N)]*M-T*N@M Try it online! Old version Old version Old version Old version Old version Detailed explanation (refers to the latest and greatest versison (88 bytes)) We start with a sizeable upfront investment to create ...


6

APL (Dyalog Extended), 2 bytes (SBCS) Anonymous tacit infix function taking \$b\$ as left argument and \$n\$ as right argument. ≢⊤ Try it online! ≢ tally the digits of ⊤ the anti-base (i.e. the representation in the given base) Note that this is wasteful in that it actually does the base conversion. APL (Dyalog Unicode), 4 bytes Anonymous tacit infix ...


5

Husk, 4 bytes Σṁdḣ Try it online! ḣ makes a range from 1 to input ṁd flatmap digits Σ sum


5

Zsh, 20 bytes My first Zsh answer, cobbled together using these very helpful posts. <<<${#v=$[[##$2]$1]} Try it online or run the test suite. Full program taking \$n\$ and \$b\$ as arguments. Commented <<< # print ${# } # length in characters of v= # set dummy variable v to $[[##$2]...


5

Proton, 67 bytes f=(n,k)=>k?f("".join(str(n.count(x))+x for x:sorted(set(n))),k-1):n Try it online! Python 3, 78 bytes f=lambda n,k:k and f("".join(str(n.count(x))+x for x in sorted({*n})),k-1)or n Try it online! -7 bytes thanks to Mukundan314


5

Jelly, 8 bytes ṢŒrUFVµ¡ Try it online! Credit to hyper-neutrino for the µ trick, and for telling me I was wrong :P Full program. Takes n then k on the command line How it works ṢŒrUFVµ¡ - Main link. Takes n on the left, k on the right µ - Last links as a monadic chain f(n): Ṣ - Sort the digits of n Œr - Run length encode UF - ...


5

Wolfram Language (Mathematica), 55 bytes ToString@#2<>#&@@@Sort@Tally@Characters@#<>""&~Nest~##& Try it online! Input ["n", k].


5

JavaScript (Node.js), 40 bytes x=>b=>b.flatMap(v=>x?x-(x=~-x/v|0)*v:[]) Try it online!


5

Python 2, \$\phi_{\Omega^\omega}(0)\cdot\omega\$, 266 bytes l=len T=lambda i,s='(',d=1:T(i/2,s+['),','('][i%2],d+i*2%4-1)if d else(eval(s)[0],i) L=lambda A,B:any(A==b or L(A,b)for b in B)or all(L(a,B)for a in A)and(l(A)-l(B),0)<(0,next((L(a,b)for a,b in zip(A,B)if a!=b),0)) def f(a,b):A,a=T(a);B,b=T(b);return(a,0)<(b,L(A,B)) Try it online! At least I ...


5

R, 45 40 39 38 bytes Or R>=4.1, 31 bytes by replacing the word function with \. function(n,k=1:n)any(c("",k[!n%%k])>n) Try it online! Using the hint (proof in @alephalpha's answer). Outputs FALSE for digit small number and TRUE otherwise. Converts list of divisors k[!n%%k] to character by prepending empty string. Then compares the vector ...


5

Python 2, 44 bytes lambda n:any(`i`>`n`>n%i<1for i in range(n)) Try it online! Outputs True/False negated. Looks for an i that's a divisor of n and is lexicographically smaller than n. The two conditions are combined into an inequality chain, connected by Python 2's willingness to compare strings and numbers (strings are bigger). This chain also ...


4

Charcoal, 5 bytes IL↨NN Try it online! Link is to verbose version of code. Works for any b>1. Unfortunately Base doesn't accept implicit arguments, so I have to explicitly input the n and b. Explanation: N Input `n` as an integer N Input `b` as an integer ↨ Convert `n` to base `b` as an array L Take the length I Cast to ...


4

Japt, 4 bytes sV l Try it here


4

Retina 0.8.2, 35 bytes \d+ $* +`\b(1+) (\1)+1* $1 $#2$* Try it online! Link includes test cases. Takes input in the order b, n. Explanation: \d+ $* Convert b and n to unary. +`\b(1+) (\1)+1* $1 $#2$* Repeatedly integer divide n by b until n is less than b. With each division, prefix a space to b. Count the total number of spaces, including the ...


4

05AB1E, 2 bytes вg First input is the base \$b\$, second input is \$n\$. Try it online or verify all test cases. Using logarithm like most other answers is 4 bytes: .n>ï Try it online or verify all test cases. Explanation: # First (implicit) input-integer = `b` # Second (implicit) input-integer = `n` в # Convert n to a base-b list g ...


4

Pyth, 4 3 bytes ljF Try it online! # implicitly output l # len of jF # convert first element in input to base second element of input -1 byte thanks to Mr. Xcoder


4

Vyxal, 7 bytes (søeRf∑ Try it Online! ( # k times... s # Sort øe # Run length encode R # Reverse each f # Flatten ∑ # Sum


4

Python 3, \$(\omega^2,28)\$ lambda a,b:(a&-a,a)<(b&-b,b) Try it online! Old version This orders by number of trailing zeros (of binary rep) first and then by the number itself.


4

Haskell, \$ \omega \cdot 2\$, 22 bytes (.q).(<).q q=odd>>=(,) Try it online! Based off Grain Ghost's Haskell answers. The function q is pointfree for q x=(odd x,x). That is, we sort numbers by whether they're odd, then the number itself, which gives the evens followed by the odds. We can generalize this idea as: Haskell, \$ \omega \cdot 4\$, 24 ...


Only top voted, non community-wiki answers of a minimum length are eligible