New answers tagged

0

05AB1E, 70 69 bytes •1OF•₂в"(4/9)"ª0.4ª©4ã"+-*/"3ãâε`.ιJ}.Δ.EQ}®¦¨ŽYyç"Γÿ4 Γ4 4! .4~"#:0K Try it online or verify all test cases. Explanation: Uses a similar approach as some of the other answers. Creates all possible combinations of four of the values \$[1,4,6,24,\frac{4}{9},0.4]\$ and three of the operators +-*/ (both of course with duplicates). •1OF• ...


0

Bash, 58 bytes eval i={1..100}';a=([i%3]=Fizz [i%5]+=Buzz);echo ${a-$i};' Try it online!


0

C (gcc), 33 bytes double f(n){return n?n*f(n-1):1;} Output: 1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600 6227020800 87178291200 1307674368000 20922789888000 355687428096000 6402373705728000 121645100408832000 2432902008176640000 51090942171709440000 1124000727777607680000 25852016738884978212864 620448401733239409999872 ...


1

Python 2, 43 bytes lambda n:reduce(int.__mul__,range(1,n+1),1) Try it online! Not the shortest Python solution but I thought it would be interesting to post a solution with reduce and int.__mul__.


1

Erlang (escript), 166 bytes i(A,B,C,D)->if A==B->C;1<2->D end. f(X)->i(X rem 3,0,"Fizz","")++i(X rem 5,0,"Buzz",""). z(0)->"";z(X)->z(X-1)++"~n"++i(f(X),"",integer_to_list(X),f(X)). z()->z(100). Try it online!


0

Python 3, 36 bytes f=lambda h,a,b:h and-~f(h>>a<<b,a,b) Try it online! I/O format is questionable, but I think the idea is interesting enough for it to be posted. Input: h: If the depth of the well is d, h is an integer whose binary representation has d digits (ignoring leading zeros). For example, if d = 4, h can be 0b1111. a: The climb ...


1

PowerShell, 50 bytes for($g,$c,$f=$args;($p+=$c)-lt$g;++$d){$p-=$f}1+$d Try it online!


1

PowerShell, 60 59 bytes -1 byte thanks to mazzy param($g,$c,$f)for(){++$d;if(($p+=$c)-ge$g){$d;exit}$p-=$f} Try it online! An optimization of root's answer. If you like this, upvote his. This runs forever on tests that are impossible. It also exits the script altogether on return so the test script is a bit sillier than normal.


1

GolfScript, 30 bytes :c-.{(c@-.{/))}{;1<}if}{;;1}if The code in the header is purely to make the input easier - it just swaps around the order into another valid inpu format, just for ease of copying examples. I thought this was going to be an 8-bte solution! And it is... kinda. Turns out we need two catches here, and each of them add a ton to make ...


0

Python 3 + SymPy, 33 bytes from sympy import* Matrix.inv_mod Try it online! SymPy's Matrix class has a method for modular inverse.


1

R, 97 83 bytes function(M,m,d){while(any(M%*%(x=matrix(T%/%m^(1:d^2-1),d))%%m-diag(d)))T=T+1;x%%m} Try it online! Pretty slow. Takes the dimension of the matrix as input. The previous version using a for loop is a bit faster. Thanks to Robin Ryder for -14 bytes. Explanation: We iterate over every number between \$1\$ and \$m^{d^2}\$, converting each to ...


7

J, 18 16 bytes (]%1+.]^5 p:[)%. Try it online! Resolves p/q mod n element-wise (instead of using det(M) to resolve the modular inverse globally). Abuses GCD of rational numbers to extract 1/q from p/q. How it works (]%1+.]^5 p:[)%. NB. left arg = modulo, right arg = matrix ( )%. NB. bind inv(matrix) as new right arg 5 p:[ ...


0

Erlang (escript), 85 bytes c(X,N)->case lists:max(integer_to_list(N))<50of true->N;_->c(X,N+X)end. c(X)->c(X,X). Try it online! Erlang (escript), 104 bytes A longer version that you can actually try 9 and 18 it online. c(N,X)->{I,_}=string:to_integer(integer_to_binary(X,2)),if I rem N==0->I;1<2->c(N,X+1)end. c(X)->c(X,1). ...


1

Java 8, 270 261 bytes M->m->{int l=M.length,R[][]=new int[l][l],T[][]=new int[l][l],d=0,s=l,r,c,k;for(;d!=1|s!=0;){for(r=l*l;r-->0;R[r/l][r%l]=d*=Math.random())d=m;for(d=1,s=r=l;r-->0;d*=T[r][r]%m)for(c=l;c-->0;s-=T[r][c]%m)for(T[r][c]=k=0;k<l;)T[r][c]+=M[r][k]*R[k++][c];}return R;} -9 bytes thanks to @ceilingcat. Keeps trying random ...


1

Magma, 34 bytes func<m,M|Matrix(Integers(m),M)^-1> No TIO for magma, though you can try it on http://magma.maths.usyd.edu.au/calc/


1

WIN+APL, 114 bytes Prompts for matrix followed by modulus. m←r←⎕⋄z←r[1;1]⋄⍎∊(¯1+1↑⍴r)⍴⊂'z←z×1 1↑r←(1 1↓r)-((1↓r[;1])∘.×1↓r[1;])÷r[1;1]⋄'⋄⌊.5+n|((1=n|z×⍳n)/⍳n←⎕)×(z←⌊.5+z)×⌹m Try it online! Courtesy of Dyalog Classic


3

Charcoal, 41 bytes FEXθ×ηη⪪E×ηη÷ιXθλη¿⬤ι⬤ζ⁼⁼λν﹪ΣEμ×ιπλθIι Try it online! Link is to verbose version of code. Takes input as \$ m, n, M \$ where \$ n \$ is the size of \$ M \$, and does not reduce its output modulo \$ m \$ (can be done at a cost of 2 bytes). Stupidly slow, so don't try this with realistic values. Explanation: FEXθ×ηη⪪E×ηη÷ιXθλη There ...


3

Sledgehammer, 6 bytes ⠑⡿⡆⠱⣁⣭ Decompresses into this Wolfram Language function: Inverse[#2, Modulus -> #1] Try it online!


3

MATL, (25?)  31 29  26 bytes My first MATL answer -5 bytes & a bug-fix (+2) thanks to Luis Mendo! The trailing . may be unnecessary - it is if there is only ever a single inverse of M with elements modulo m. :inZ^!"&G@[]eY*w\tZyXy=?@. A full program which prints the elements in row major order separated by newlines. Try it online! - ...


2

Jelly, (21?) 22 bytes The trailing Ṫ may be unnecessary - it is if there is only ever a single inverse of M with elements modulo m. Ḷṗ⁹L²¤ṁ€⁹æ×%³L⁼þ`$ƑɗƇṪ A full program printing the result. Try it online! - Too slow for any of the given test cases (the 35 case took ~20 minutes locally). 11 bytes (but floating point output): Using Bubler's observation (...


2

R, 128 bytes function(x,m,n)t(round(which((1:m*det(x))%%m<1.5)[1]*outer(1:n,1:n,Vectorize(function(a,b)det(x[-a,-b,drop=F])*(-1)^(a+b))))%%m) Try it online! A function taking three arguments, x = the matrix, m = the modulus and n the number of rows of x. Returns a matrix. Uses the same method as my Jelly answer.


10

R, 68 bytes function(M,m,n,A=M){while(any(A%*%M%%m!=diag(n)))A[]=rpois(n^2,9) A} Try it online! Strikingly slow. Will most likely time out for all test cases on TIO, but is guaranteed to give an answer eventually. Works by rejection sampling: generates random matrices A, with each value taken from a \$Poisson(9)\$ distribution, until a solution is found. ...


4

Jelly, 25 bytes ÆḊ×Ɱ⁹%ỊTḢ×ZÆḊ-Ƥ$-ƤNÐe⁺€Zʋ Try it online! A dyadic link taking the matrix as its left argument and the modulus as its right. Returns a matrix. Append a % to get it within the range 0, m


4

SageMath, 48 33 bytes Saved 15 bytes thanks to ovs!!! lambda m,M:~Matrix(Integers(m),M) Nothing on TIO for SageMath unfortunately. Modular inverse of a matrix M (input as a Python list of lists) mod m.


4

JavaScript (ES6),  209  206 bytes Takes input as (modulo)(matrix). This transposes the matrix of cofactors (resulting in the adjugate) and multiply it by the inverse of the determinant of \$M\$ modulo \$m\$. m=>M=>M.map((r,y)=>r.map((_,x)=>((g=k=>(++k*D(M)%m+m)%m-1?g(k):x+y&1?-k:k)``*D(h(M,x).map(r=>h(r,y)))%m+m)%m),h=(a,n)=...


6

Wolfram Language (Mathematica), 23 bytes ¯\_(ツ)_/¯ the answer was in the documentation of Modulus Inverse[#2,Modulus->#]& Try it online!


2

Roj, 178 173 171 161 160 156 153 152 141 bytes Because I am completely new to Roj, there may still be potential golfs out here. readint I;C=0;while 1 do C=C+I;i=C;L=0<1;while i do c=0;while c<=i/10 do c=c+1 end;c=c-1;L=L and(i-10*c)<2;i=c end;if L do out C;halt end end Explanation It's made primarily for me to find potential golfs. Indented: ...


0

Symja, 140 134 128 bytes For(i=1,i<101,i++,If(Mod(i,5)==0,s=s<>"Fizz");If(Mod(i,3)==0,s=s<>"Buzz");If(Mod(i,5)*Mod(i,3)!=0,s=s<>ToString(i));s=s<>"\n");s Y'all can try it online here Just a standard fizzbuzz approach. This is tweetable BTW, so there's that too.


1

Julia 1.0, 38 bytes f(k,n=k)="10"⊇repr(n) ? n : f(k,n+k) Try it online!


1

JavaScript (Node.js), 50 bytes (x,i=1,g=v=>v.toString(2))=>g(i)/x%1?f(x,++i):g(i) Try it online!


Top 50 recent answers are included