Skip to main content

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
15 votes
4 answers
694 views

Simulate weathering of a rock

Inspired by my geography class, Sandboxed Simulate weathering / erosion. Input Input will be given as a string of any 2 characters (or see below) you like in the shape of the rock (here i use spaces ...
zoomlogo's user avatar
  • 1,655
19 votes
6 answers
795 views

Is it an elementary matrix?

Consider a linear system of equations, in \$n\$ unknowns, expressed as $$A \textbf x = \textbf b$$ where \$A \in M_{n,n}(\mathbb Z)\$ is an \$n \times n\$ matrix of integers, \$\textbf x\$ is a column ...
caird coinheringaahin g's user avatar
20 votes
13 answers
2k views

Compute matrix blockiness

Consider a non-empty binary matrix M and a natural number n. For the purposes of this challenge, M is said to have blockiness n if it can be built using adjacent square blocks of size n, where each ...
Luis Mendo's user avatar
  • 105k
16 votes
10 answers
819 views

Remove submatrices

Given two integer matrices a and b, your challenge is to replace any occurences of b in <...
emanresu A's user avatar
  • 38.8k
6 votes
1 answer
594 views

Fast Matrix Multiplicator Evaluator

A triplet of real tensors \$(A,B,C)\$ of size \$\gamma \times \gamma \times \sigma\$ represents a matrix multiplication algorithm with \$\sigma\$ elementary multiplications iff the following function ...
yejaxey's user avatar
  • 69
21 votes
9 answers
2k views

Bird's Algorithm for Computing Determinants

There is a division-free algorithm for computing determinants published by R.S.Bird in 2011 that uses only matrix multiplications. Given a \$n×n\$ matrix \$X\$, the matrix \$Y=μ(X)\$ is another \$n×n\$...
Vinícius Mello's user avatar
21 votes
22 answers
2k views

Checkered grid with X mark

Challenge Given two integer values \$a \ge 2\$ and \$0 \le b < a\$, generate a \$(2a-1) \times (2a-1)\$ matrix consisting of the integers 0, 1, and 2 as follows: Create a checkerboard of 0s and 1s ...
Bubbler's user avatar
  • 77k
25 votes
19 answers
2k views

Double trace of a square matrix

Inspired by a question (now closed) at Stack Overflow. Given a square matrix, let its double trace be defined as the sum of the entries from its main diagonal and its anti-diagonal. These are marked ...
Luis Mendo's user avatar
  • 105k
13 votes
8 answers
1k views

Find the number of paths in a n×n grid

Information Given a non-negative odd integer (let's call it \$n\$), find the number of all possible paths which covers all squares and get from the start to end on a grid. The grid is of size \$n\$×\$...
zoomlogo's user avatar
  • 1,655
17 votes
15 answers
1k views

Drop down the numbers

This was inspired by Apply gravity to this matrix Your challenge is to input a matrix with non-negative one-digit integers and drop down the 1's down 1 column, the 2's down 2 columns, the 3's down 3 ...
Larry Bagel's user avatar
  • 4,193
23 votes
30 answers
4k views

Apply gravity to this matrix

This was inspired by this question. Given an \$m\times n\$ matrix of \$0\$'s and \$1\$'s, apply "gravity" to it. This means to drop down all the \$1\$'s as if they were affected by gravity. ...
0xff's user avatar
  • 829
18 votes
4 answers
709 views

Calculate the integer square root of a matrix

Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For ...
caird coinheringaahin g's user avatar
21 votes
11 answers
2k views

Is this a Jordan matrix?

Background A Jordan matrix is a block-diagonal matrix where each block on the diagonal has the structure of $$ \begin{bmatrix} \lambda & 1 & 0 & \cdots & 0 \\ 0 &...
Bubbler's user avatar
  • 77k
29 votes
28 answers
2k views

Recursive Z-matrix

Originally from a CMC I proposed for the last BMG event Challenge Given a non-negative integer \$n\$, create a 2D array of size \$2^n × 2^n\$ which is generated in the following manner: Divide the ...
Bubbler's user avatar
  • 77k
16 votes
10 answers
719 views

To raise \$ e \$ to the power of a matrix

Inspired by this 3Blue1Brown video Given a square matrix \$ M \$, compute its matrix exponential \$ \exp(M) \$, which is defined, using an extension of the Maclaurin series for \$ e^x \$, as $$ \exp(M)...
pxeger's user avatar
  • 23.9k
18 votes
11 answers
2k views

Count my Pluses

Your task is, to count how many pluses I have. What Pluses? The no plus: 0 Points - The naïve Plus: 1 Point + The double ...
math scat's user avatar
  • 9,408
17 votes
7 answers
1k views

Drop some boxes

Say I have a pile of boxes: AAA BBB I can create it in two steps: BBB ↓ (empty) --- AAA ↓ BBB But with this: ...
emanresu A's user avatar
  • 38.8k
16 votes
17 answers
837 views

Square chunk my matrix

Your challenge is to write a function/program that takes a matrix of integers m and a number n as input and: Splits m into n by n chunks Replaces each chunk with the most common value in that chunk (...
emanresu A's user avatar
  • 38.8k
26 votes
9 answers
2k views

Is it a valid Parker Square

5 Years ago, this happened, and then it became sort of a meme. Challenge The Challenge today is, to check if a "magic square" is a valid parker square. What is a Real Magic square? All the ...
math scat's user avatar
  • 9,408
31 votes
55 answers
2k views

Generate this number table

Given an integer \$1 < n < 10 \$ generate a table like below. For \$n = 5\$, 1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5 For \$n = 8\$, ...
BadCoder's user avatar
  • 461
9 votes
15 answers
865 views

Construct a Modulo Multiplication Table

Consider a n x n multiplication table and replace each item with its remainder of division by n. For example, here is a ...
polfosol ఠ_ఠ's user avatar
26 votes
24 answers
3k views

I'm Lazy*: Top-left align my text

* and don't have a word processor with top-left align support :D Take several lines of input, with at least four unique characters of your choice including newline and space. The input can also be ...
Wezl's user avatar
  • 1,478
22 votes
2 answers
1k views

Minecraft piston pushing

In Minecraft, pistons are blocks that can move other blocks. However, they can only move at most twelve blocks, and won't work at all if any obsidian is in the way. Also, slime blocks are sticky and ...
emanresu A's user avatar
  • 38.8k
27 votes
47 answers
3k views

Output a Latin Square

An \$n\times n\$ Latin Square is a grid containing exactly \$n\$ distinct values where the values in each row and column are distinct. For example, $$\begin{matrix} A & B & C \\ C & A &...
caird coinheringaahin g's user avatar
13 votes
5 answers
629 views

The Game of Cat And Mice | With Matrices

Challenge This coding challenge is to figure out how many rounds the cat can live. In a \$4\times4\$ matrix, there are a number of mice and exactly 1 cat. Example: $$ \begin{array} {|r|r|}\hline 🐭 &...
math scat's user avatar
  • 9,408
16 votes
5 answers
755 views

Dominate a zero-sum game

Consider a zero-sum game with 2 contestants. Each round, each contestant chooses, independently of each other, one of \$n \ge 2\$ different choices. Depending on the two chosen choices, one player is ...
caird coinheringaahin g's user avatar
45 votes
21 answers
2k views

Summon the sevens

You are given a \$3\times3\$ square matrix where each cell is any digit between \$0\$ and \$9\$ except \$7\$. Your task is to figure out the minimum number of digits that must be replaced with \$7\$'s ...
Arnauld's user avatar
  • 193k
9 votes
3 answers
1k views

Validating a Battleship board

Do you know the game Battleship? Well, I want to play with my little brother, but before we can begin we need to set up our ships on the board. This is your input. Now, we need to check that the ships ...
Rocky cohn's user avatar
29 votes
10 answers
2k views

Help Stack Exchange transpose tables

Stack Exchange doesn't know how to transpose tables. Let's help. Given a markdown table, transpose it. Input assumptions: There will be at least two rows (including header) and two columns Either all ...
Adám's user avatar
  • 30.4k
29 votes
23 answers
4k views

Calculate the inverse of a matrix

Somehow, we don't yet have a challenge for finding the inverse of an arbitrarily-sized square matrix, despite having ones for 3x3 and 4x4, as well as a more complex version. Your task is, given a ...
caird coinheringaahin g's user avatar
11 votes
2 answers
327 views

Thin Paper Folding

Thin Paper Folding This is a "lighter" version of the challenge Paper Folding for the win. This challenge is being posted as a different challenge with many modifications in order to try ...
SomoKRoceS's user avatar
  • 1,425
29 votes
31 answers
3k views

Antisymmetry of a Matrix

A matrix is antisymmetric, or skew-symmetric, if its transpose equals its negative. The transpose of a matrix can be obtained by reflecting its elements across the main diagonal. Examples of ...
golf69's user avatar
  • 2,059
18 votes
1 answer
396 views

Paper Folding for the win

Paper Folding for the win "How many times can you fold a paper?" - This well known question led to many arguments, competition, myths and theories. Well, the answer to that question depends ...
SomoKRoceS's user avatar
  • 1,425
15 votes
14 answers
1k views

Help me accelerate linear recurrence relation!

Background A linear recurrence relation is a description of a sequence, defined as one or more initial terms and a linear formula on last \$k\$ terms to calculate the next term. (For the sake of ...
Bubbler's user avatar
  • 77k
20 votes
2 answers
610 views

Checkerboard the Matrix

Task Given a matrix, your program/function should output a row-equivalent matrix in checkerboard form ( \$A_{ij}=0\$ if and only if \$i+j\$ is odd). Two matrices are defined to be row-equivalent if ...
fireflame241's user avatar
  • 16.3k
19 votes
10 answers
2k views

Complete the Magic Square

Background A magic square is an n×n matrix consisting of one of each of the integers from \$1\$ to \$n^2\$ where every row, column, and diagonal sum to the same ...
fireflame241's user avatar
  • 16.3k
11 votes
0 answers
276 views

Cover positions with snakes of same 'colour'

Imagine a grid where the origin square \$(0,0)\$ is at the top left of the screen, and positive \$x\$ is rightwards whereas positive \$y\$ is downwards. Coloured squares are at various positions on ...
lightlyheld's user avatar
14 votes
5 answers
986 views

What is the Subspace Dimension?

Challenge Given the Cartesian coordinates of two or more distinct points in Euclidean n-space (\$\mathbb{R}^n\$), output the minimum dimension of a flat (affine) subspace that contains those points, ...
fireflame241's user avatar
  • 16.3k
26 votes
21 answers
2k views

Logo Pack LAPACK

This is the logo for LAPACK, a widely used software library for numerical linear algebra. Your task is to print the logo (color and matrix brackets not required) as this exact string. Trailing ...
qwr's user avatar
  • 12.1k
18 votes
4 answers
353 views

Identify the smallest possible tile in the matrix

Challenge Given a matrix of digits (0-9), find the smallest (in terms of area) rectangular matrix of digits where one or more copies of itself, possibly rotated, can tile the original matrix. ...
Bubbler's user avatar
  • 77k
2 votes
2 answers
205 views

Create a text image by manual automation

Challenge Premise It's 2006, and Alice is trying to send Bob their her completed notes on their newly ended expeditions into the labyrinthine school library, which the two of them found suffers from a ...
subdermatoglyphic's user avatar
22 votes
6 answers
2k views

The matrix has U

Given a matrix of size at least 3×3 formed by positive integers, determine if it contains at least one "U" pattern, defined as ...
Luis Mendo's user avatar
  • 105k
12 votes
7 answers
743 views

Toroidally magnify-blur a matrix

Task Given a matrix of numbers \$M\$ with \$r\$ rows and \$c\$ columns, and the magnification factor \$n\$, build the matrix with \$rn\$ rows and \$cn\$ columns where the original elements are spaced ...
Bubbler's user avatar
  • 77k
12 votes
2 answers
360 views

Positioning a fake mirror for best effect

Challenge Premise Consider a mosaic of \$m\times n\$ tiles, in \$k\$ unique colours designated by integers. Example (\$3\times6\$, four colours): ...
subdermatoglyphic's user avatar
18 votes
3 answers
710 views

Make a rectangle from a collection of (sliced) squares

Inspired by Make a Rectangle from a Triangle. Task There is a famous formula on the sum of first \$n\$ squares: $$ 1^2 + 2^2 + \dots + n^2 = \frac{n(n+1)(2n+1)}{6} $$ It is known that this number ...
Bubbler's user avatar
  • 77k
22 votes
17 answers
3k views

Make a Rectangle from a Triangle

You can depict a triangular number, T(N), by writing one 1 on a line, then two 2's on the line below, then three 3's on the line below that, and so on until N N's. You end up with a triangle of T(N) ...
Calvin's Hobbies's user avatar
19 votes
16 answers
1k views

(RGS 4/5) Inverting matrices modulo m

Task Given an integer matrix M and a modulus m, find an inverse of M modulo ...
RGS's user avatar
  • 14.1k
17 votes
10 answers
799 views

Decomposition of a matrix in \$ SL_2(\mathbb{Z}) \$

Background The special linear group \$ SL_2(\mathbb{Z}) \$ is a multiplicative group of \$ 2 \times 2 \$ matrices whose elements are integers and determinant is 1. It is known that every member of \$...
Bubbler's user avatar
  • 77k
23 votes
3 answers
868 views

Find the number of n-by-n (-1, 0, 1) matrices with zero permanent as quickly as possible

The permanent of an \$n\$-by-\$n\$ matrix \$A = (a_{i,j})\$ is defined as: $$\operatorname{perm}(A)=\sum_{\sigma\in S_n}\prod_{i=1}^n a_{i,\sigma(i)}$$ For a fixed \$n\$, consider the \$n\$-by-\$n\$ ...
matrix42's user avatar
  • 685
20 votes
21 answers
3k views

Clockwise matrix rotation

The title pretty much describes it all. Given as input a \$n \times m\$ matrix and an integer \$i\$ create a complete function/program that returns the matrix \$i\$ times clockwise rotated by \$90^\...
game0ver's user avatar
  • 671