Questions tagged [matrix]

This tag is for challenges involving matrices. A matrix, also known as a 2D array, is a list of numbers arranged in a rectangle with rows and columns.

Filter by
Sorted by
Tagged with
9 votes
6 answers
1k views

Calculate the Kronecker sum of two matrices

In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed. A Kronecker product has the ...
4 votes
1 answer
183 views

Find the last position in a matrix walking like a spiral [closed]

This question will be deleted soon, do not read/answer it Introduction Given one matrix A x A and a number of movements N. ...
  • 2,763
24 votes
24 answers
3k views

Diamondize a Matrix

Given a matrix, output a representation of the matrix where the top left element is on top, the anti-diagonal is the central row and the bottom right element is at the bottom. For example, consider ...
  • 36.8k
15 votes
18 answers
1k views

Sorting rectangular matrices

Given a matrix A, we can say that it is "sorted" if each row and column of A is sorted (ascending left-to-right for ...
user avatar
19 votes
7 answers
1k views

Hilbert-Curvify a Matrix

Inspired by this question Another way to unroll a 2D image into a 1D string is to use an Hilbert Curve. There are many version of this curve, depending on the number of iterations used while ...
23 votes
3 answers
875 views

Reconstruct a zigzagified matrix

As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction: Your task is to take the unrolled vector along with the matrix ...
45 votes
11 answers
5k views

Zigzagify a Matrix

As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction: Your task is to take a matrix (not necessarily square) and return ...
20 votes
7 answers
1k views

Is this a submatrix?

This is the 2-dimensional generalisation of this challenge. For our purposes, one matrix (or 2D array) A is considered a submatrix of another matrix B, if A can be obtained by completely removing a ...
17 votes
4 answers
910 views

Rotate every 2x2 block in a matrix

The Challenge Given a n x m matrix with n > 1 and m > 1 filled with integers 1 2 3 4 ...
  • 6,791
16 votes
4 answers
954 views

Rotate every row and column in a matrix

The Challenge Given a n x n matrix of integers with n >= 2 1 2 3 4 and a list of integers with exactly ...
  • 6,791
26 votes
24 answers
1k views

Vandermonde Determinant

Given a vector of \$n\$ values \$(x_1,x_2,x_3,\ldots,x_n)\$ return the determinant of the corresponding Vandermonde matrix \$V(x_1, x_2, \ldots, x_n) = \begin{bmatrix}1 & x_1 & x_1^2 & x_1^...
  • 43.2k
18 votes
12 answers
1k views

Recursive 2x2 determinant

The determinant of a 2 by 2 matrix a b c d is given by ad - bc. Given a matrix of digits with dimensions 2n by 2n, n ≥ 1, ...
  • 61.1k
26 votes
14 answers
1k views

Fibonacci-style matrix expansion

For each row and then column of a matrix, we can add an extra entry with the sum of the last two entries in that row or column. For example with the following input matrix: ...
44 votes
90 answers
5k views

Construct the Identity Matrix

The challenge is very simple. Given an integer input n, output the n x n identity matrix. The identity matrix is one that has <...
  • 1,317
19 votes
6 answers
1k views

Cofactor Matrices

The cofactor matrix is the transpose of the Adjugate Matrix. The elements of this matrix are the cofactors of the original matrix. The cofactor (i.e. the element of the cofactor matrix at row i and ...
  • 36.8k
14 votes
12 answers
1k views

Construct a companion matrix

You have a number of polynomials who are lonely, so make them some companions (who won’t threaten to stab)! For a polynomial of degree n, there is an ...
  • 1,035
10 votes
2 answers
3k views

Reduced Row-Echelon Form of a Matrix

The goal of this challenge is to create a program that takes in a matrix and outputs its reduced row-echelon form. A matrix is in reduced row-echelon form if it meets all of the following ...
  • 7,404
12 votes
4 answers
631 views

Multiply Pauli Matrices

The Pauli matrices are a set of 2x2 matrices which appear very commonly in quantum physics (no, you don't need to know any quantum physics for this challenge). If we include the identity in the set, ...
-3 votes
1 answer
523 views

Find the inverse of a matrix

Write a full program to calculate the inverse of a 4-by-4 matrix. Rules The sixteen values of the initial matrix must be hard-coded to variables, as follows: ...
  • 10.8k
15 votes
4 answers
1k views

Solve a 2x2 Eigensystem

For those with a little linear algebra background, the challenge is as simple as this: determine the eigenvalues and eigenvectors of a given complex 2x2 matrix. You may skip ahead to The Challenge for ...
8 votes
9 answers
2k views

Shortest C \ C++ function to generate -1, 0 ,1 [closed]

Let a function receive two integers i and j between 0 and ...
  • 1,033
17 votes
10 answers
530 views

Ascending matrix

The "ascending matrix" is an infinite matrix of whole numbers (0 included) in which any element is the smallest available element which has not been previously used on the respective row and column: <...
6 votes
9 answers
5k views

matrix determinant [closed]

Calculate the determinant of an n x n matrix. Rules read matrix from standard input write to standard output do not use ready solutions from library or language input: columns separated by any space ...
11 votes
16 answers
1k views

Numbers, Sums, Products

Given a 20×20 grid of non-negative integers, find a 3×3 sub-grid where the product of the sums of the individual lines hits the maximum. Spoken in formulas: Given the 3×3 sub-grid $$\mathfrak{U} = \...
  • 12.8k

1 2 3 4 5
6