Skip to main content
Share Your Experience: Take the 2024 Developer Survey
29 votes

Determinant of an Integer Matrix

Jelly, 15 bytes LŒ!ðŒcIṠ;ị"Pð€S Try it online! How it works ...
Leaky Nun's user avatar
  • 49.7k
19 votes

Find the inverse of a 3 by 3 matrix

MATL, 54 bytes th3LZ)t,3:q&XdpswP]w-lw/GtY*tXdsGXdsUw-IXy*2/+GtXds*-* Try it online! Just to keep it interesting, doesn't use the inbuilt matrix division or ...
Sundar R's user avatar
  • 6,612
17 votes

Billiard balls collision

Python 3, 67 66 bytes, 53 bytes def f(p,v,q,w):p-=q;d=((v-w)/p).real*p;return v-d,w+d Try it online! -1 byte thanks to @ngn -13 bytes thanks to @Neil This ...
Joel's user avatar
  • 1,751
16 votes

Is the matrix rank-one?

Jelly, 6 bytes ẸÐfÆrE Try it online! How it works ...
Dennis's user avatar
  • 210k
14 votes

Determinant of an Integer Matrix

Jelly, 16 15 12 10 bytes Ḣ×Zß-Ƥ$Ṛḅ- Uses Laplace expansion. Thanks to @miles for golfing off 3 5 bytes! Try it online! How it works ...
Dennis's user avatar
  • 210k
14 votes

Eigenvalues of a Matrix

Haskell, 576 554 532 507 bytes No built-ins! ...
ბიმო's user avatar
  • 16.8k
14 votes

Calculate the Hafnian as quickly as possible

Haskell ...
Christian Sievers's user avatar
14 votes

Find the inverse of a 3 by 3 matrix

APL(Dyalog Classic),1 byte Try it online! if a flat lis is required this is 8 bytes ,∘⌹3 3∘⍴ Try it online!
jslip's user avatar
  • 791
14 votes

Are these the basis vectors?

Octave, 43 41 39 bytes @(B,v)(r=rank(B))-rows(B)|r-rank([B;v]) Anonymous function that inputs the set of vectors as a matrix B with each vector in a row, and v as ...
Luis Mendo's user avatar
  • 105k
13 votes

Verify Eigenpairs

Mathematica, 10 bytes #2.#==#3#& Takes input like {vector, matrix, scalar} and returns a boolean.
Martin Ender's user avatar
12 votes

Determinant of an Integer Matrix

R, 3 bytes Trivial Solution det Try it online! R, 94 92 89 bytes re-implemented solution outgolfed by Jarko Dubbeldam ...
Giuseppe's user avatar
  • 28.6k
11 votes

Verify Eigenpairs

MATL, 7 bytes *i2GY*= Inputs in order: l,v,A. ...
Sanchises's user avatar
  • 9,496
11 votes
Accepted

Verify Eigenpairs

Jelly, 5 bytes æ.⁵⁼× This is a triadic, full program. Try it online! How it works ...
Dennis's user avatar
  • 210k
11 votes

Determinant of an Integer Matrix

Haskell, 71 bytes -3 bytes thanks to Lynn. Another one bytes the dust thanks to Craig Roy. ...
totallyhuman's user avatar
  • 17.2k
11 votes

Characteristic polynomial

SageMath, 3 bytes 5 bytes saved thanks to @Mego fcp Try it online! Takes a Matrix as input. ...
Uriel's user avatar
  • 13.2k
11 votes

Billiard balls collision

JavaScript (Node.js), 90 88 bytes (m,n,o,p,q,r,s,t,u=(q-=m)*q+(r-=n)*r,v=o*q+p*r-s*q-t*r)=>[o-(q*=v/u),p-(v*=r/u),s+q,t+v] Try it online! Link includes test ...
Neil's user avatar
  • 171k
11 votes

Diagonalize a vector

K (ngn/k), 7 bytes {x*=#x} My first K post. I tried real hard to make a Bubbler train work here but failed. Try it online!
south's user avatar
  • 1,730
10 votes

Arnold's Cat Map

Jelly, 9 bytes Zṙ"JC$µ2¡ Try it online! The coordinates are as in the answer. Explanation ...
lynn's user avatar
  • 68.7k
10 votes

Is this a Jordan matrix?

JavaScript, 58 bytes a=>a.some((r,y)=>r.some((c,x)=>(r/(r=c)==a[x][x])/-y--<c)) Try it online! When c==0 ...
tsh's user avatar
  • 34.9k
9 votes

Arnold's Cat Map

MATL, 23 bytes tt&n:qt&+&y\tb+&y\b*+Q( The (0,0) point is upper left, as in the examples in the challenge ...
Luis Mendo's user avatar
  • 105k
9 votes

Symbolic matrix multiplication

Haskell, 62 61 59 bytes e=[]:e z=zipWith a!b=[unwords.z(++)r<$>foldr(z(:))e b|r<-a] Try it online! Example usage: ...
Laikoni's user avatar
  • 26.2k
9 votes

Characteristic polynomial

Octave, 16 4 bytes @BruteForce just told me that one of the functions I was using in my previous solution can actually do the whole work: poly Try it online! ...
flawr's user avatar
  • 43.8k
9 votes

Generalized matrix trace

R, 40 30 bytes function(m,F)Reduce(F,diag(m)) Try it online! Verify the test cases. Traverses down the diagonal, so left-to-right in this case. For arithmetic ...
Giuseppe's user avatar
  • 28.6k
9 votes

Codegolf the Hafnian

R, 150 142 127 119 bytes function(A,N=nrow(A),k=1:(N/2)*2)sum(apply(gtools::permutations(N,N),1,function(r)prod(A[cbind(r[k-1],r[k])])))/prod(k) Try it online! ...
Giuseppe's user avatar
  • 28.6k
9 votes

Find the inverse of a 3 by 3 matrix

R, 51 35 27 8 5 bytes solve Try it online! First go at doing one of these golf challenges. Sorry if my formatting is wrong! Saved a total additional 11 bytes ...
Robert S.'s user avatar
  • 1,323
9 votes

Hankel transform of an integer sequence

APL (Dyalog Extended), 10 bytes Anonymous tacit infix function taking 1-indexed \$i\$ as left argument and the sequence \$\{a_n\}\$ as right argument. ⌂det∘↑⊣↑,/ ...
Adám's user avatar
  • 30.3k
8 votes

Is the matrix rank-one?

Haskell, 50 bytes r takes a list of lists of Integers and returns False if the matrix has ...
Ørjan Johansen's user avatar
8 votes

Determinant of an Integer Matrix

Wolfram Language (Mathematica), between 14 and 42 bytes We've had a 3-byte built-in and a 53-byte solution that completely avoids built-ins, so here are some weirder solutions somewhere in between. ...
Not a tree's user avatar
  • 3,206
8 votes

Generalized matrix trace

Haskell, 39 bytes Thanks @Laikoni for helping me fix the previously invalid solution! f!m=foldl1 f[h|h:_<-zipWith drop[0..]m] Associates to the left, try it ...
ბიმო's user avatar
  • 16.8k
8 votes

Codegolf the Hafnian

Pyth, 24 bytes sm*Fmc@@Qhkek2d{mScd2.pU Try it here! Old version, 35 bytes *c1**FK/lQ2^2Ksm*Fm@@Q@[email protected] Try it here!
Mr. Xcoder's user avatar
  • 42.4k

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