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
5
votes
0answers
112 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 ...
19
votes
7answers
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 &...
28
votes
23answers
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 ...
12
votes
7answers
267 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)...
18
votes
11answers
1k 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 ...
16
votes
7answers
998 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: ...
14
votes
16answers
721 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 (...
25
votes
9answers
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 ...
23
votes
36answers
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\$, ...
9
votes
15answers
707 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 ...
26
votes
21answers
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 ...
22
votes
2answers
929 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 ...
22
votes
42answers
2k 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 &...
12
votes
4answers
474 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 🐭 &...
16
votes
5answers
722 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 ...
45
votes
21answers
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 ...
8
votes
3answers
607 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 ...
28
votes
10answers
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 ...
28
votes
20answers
3k 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 ...
10
votes
1answer
228 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 ...
26
votes
24answers
2k 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 ...
18
votes
1answer
348 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 ...
14
votes
13answers
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 ...
19
votes
1answer
466 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 ...
19
votes
10answers
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 ...
9
votes
0answers
169 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 ...
14
votes
5answers
964 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, ...
26
votes
21answers
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 ...
15
votes
3answers
279 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. ...
2
votes
2answers
181 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 ...
21
votes
6answers
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 ...
12
votes
7answers
695 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 ...
11
votes
1answer
310 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): ...
17
votes
3answers
688 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 ...
22
votes
17answers
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) ...
19
votes
16answers
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 ...
17
votes
10answers
487 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 \$...
21
votes
2answers
704 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\$ ...
19
votes
21answers
2k 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^\...
11
votes
17answers
9k views

Euclidean Distance Between Two Matrices

Your task is to write the shortest algorithm in a language of your choosing that accomplishes the following: Given two matrices it must return the euclidean distance matrix. The euclidean distance ...
25
votes
14answers
3k views

ASCII texturing

Write a function or a full program that applies an ASCII texture to a 2d shape. Inputs: shape, texture, dimensions(optionally). Both Shape and Texture can be given by any convenient method (2d ...
47
votes
14answers
5k views

In Flanders Fields

Today is November 11th, which for many regions is Remembrance Day. If you don't know anything about the history or context of Remembrance Day, you can read about it in the wiki page, but it's not ...
31
votes
4answers
1k views

Expand a recursive pattern

Given a description of the base state of a recursive ASCII pattern, output an expanded state somewhere along the recursion steps. More specifically: Let the following be an example: ...
28
votes
17answers
4k views

Implement the Max-Pooling operation from Convolutional Neural Networks

In convolutional neural networks, one of the main types of layers usually implemented is called the Pooling Layer. Sometimes, the input image is big (and therefore time consuming especially if you ...
32
votes
6answers
2k views

Slash the matrix

You are given a matrix of forward and back slashes, for instance: //\\ \//\ //\/ A slash cuts along the diagonal of its cell corner-to-corner, splitting it in ...
2
votes
0answers
85 views

Generate square sub-matrices of 1's [duplicate]

Back again, stealing another question from stackoverflow. You are given a list of integers >= 0. Generate in order square 1-matrices where the side length is given by the list entry of the current ...
27
votes
9answers
4k views

Implement the 2D Hadamard Transform

The Hadamard transform works similarly to the Fourier transform: it takes a vector and maps it to its frequency components, which are the Walsh functions. Instead of sine waves in the Fourier ...
36
votes
24answers
6k views

I transpose the source code, you transpose the input!

Rip-off of a rip-off of a rip-off of a rip-off. Go upvote those! Your task, if you wish to accept it, is to write a program/function that outputs/returns its input/argument¹. The tricky part is that ...
21
votes
20answers
2k views

Reorder a matrix, twice

You are given a square \$n \times n\$ matrix \$A\$, and a list (or vector) \$u\$ of length \$n\$ containing the numbers \$1\$ through \$n\$ (or \$0\$ through \$n-1\$). Your task is to reorder the ...
16
votes
1answer
354 views

Decompose Commutators

A theorem in this paper1 states that every integral n-by-n matrix M over the integers with trace M = 0 is a commutator, that means there are two integral matrices A,B of the same size as M such that M ...

1
2 3 4 5