# 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.

274 questions
Filter by
Sorted by
Tagged with
2k views

• 5,020
744 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 ...
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 ...
• 171k
887 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 ...
• 113
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.4k
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 ...
250 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 ...
• 1,405
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 ...
• 2,009
363 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 ...
• 1,405
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 ...
• 66.1k
567 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 ...
• 16.1k
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 ...
• 16.1k
217 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 ...
• 513
976 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, ...
• 16.1k
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 ...
• 11.2k
289 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. ...
• 66.1k
196 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 ...
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 ...
• 101k
724 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 ...
• 66.1k
323 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): ...
701 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 ...
• 66.1k
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) ...
• 88.2k
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 ...
• 13.8k
625 views

• 651
11k 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 ...
• 187
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 ...
• 9,856
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 ...
• 40.3k
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: ...
• 40.3k
5k 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 ...
• 1,199
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 ...
• 14.9k
86 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 ...
• 617
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 ...
• 663
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 ...
• 28.4k
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 ...
• 9,346
381 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 ...
• 43.2k
1k views

### An array battle with odd secret powers

Here is a relatively simple two dimensional array challenge. Imagine a battlefield of 625 foot soldiers. You command the odd troops, but unfortunately the strength of the even troops overwhelms you. ...
• 153
1k views

### Subtract the Folded Matrix

Challenge: Given an NxN matrix where $N\geq2$ and one of eight distinct 'folding options', output a 2D array/list with the subtracted values. The eight folding options are: left-to-right; right-to-...
• 109k
2k views

### Overlapping String-Blocks

Challenge: Given a list of multi-line strings, overlap them (in the top-left) and output the result. Example: Input: ["aaaa\naaaa\naaaa\naaaa","bb\nbb\nbb","c"] ...
• 109k
2k views

### Make all the squares explode

You are given a square matrix of width $\ge2$, containing square numbers $\ge1$. Your task is to make all square numbers 'explode' until all of them have disappeared. You must print or return the ...
• 171k
5k views

### Binary Numbers Magic Trick

The challenge is simply; output the following six 2D integer arrays: ...
• 109k
1k views

### Slither Like a Snake

The Idea We've done matrix spirals before, and full rotations, and even diagonal rotations, but not, as far as I can find, snake rotations! What is a snake rotation? Imagine the rows of a matrix ...
• 29k
2k views

### Is this Pascal's Matrix?

In Pascal's triangle each number is the sum of the two numbers directly above it, treating empty spots as zero: By rotating the triangle, we can cut out square matrices of varying sizes and rotations ...
• 25.2k
598 views

### Black Hole challenge from codewars

I came across this challenge from codewars. I wish to know how to solve this problem. The problem description is given below. Its elements are in range[1..n^2]. The matrix is filled by rings, from the ...
• 173
372 views

### Can this container hold this much liquid?

Can this container hold this much liquid? Challenge Synopsis As you most likely know, liquids have an indefinite shape and a definite volume. As such, they always take the shape of their container. ...
• 956
2k views

### Exploding Numbers

sandbox (deleted) Lets define a matrix of 9s as: $$N = \begin{bmatrix} 9&9&9\\9&9&9\\9&9&9 \end{bmatrix}$$ Lets define an exploding number as a number at position $(x,y)$...