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
3 votes
4 answers
77 views

Find the representative submatrix

Note: This is a more limited version of a challenge from 2014 that only received one answer. That challenge required participants write two programs; this challenge is essentially one half of that. ...
  • 8,936
16 votes
10 answers
1k views

Find the box by its corners

Given a matrix of integers \$M\$ and a list of four integers \$L\$, find the sub-matrix \$N\$ whose corners are given by \$L\$ and return the sum of its elements. Suppose you're given the list \$L = [...
  • 8,936
16 votes
10 answers
1k views

Make the cheapest cut

“Cut” a matrix of integers on the line where the sum of the absolute differences of “severed” neighbors is the least. Example Consider this matrix: ...
  • 8,936
14 votes
14 answers
1k views

Minimum rotation to get the maximum value

I recently solved a coding challenge in one of the challenge papers that my IT teacher gave to us. It was a seemingly simple, but fun challenge, so I thought it will make fun golfing. The task Given ...
  • 1,675
13 votes
7 answers
727 views

Box blur the string

Box blur is a simple operation for blurring images. To apply box blur, simply replace each pixel with the average of its and the surrounding 8 pixels' values. Consider, for example, the following ...
  • 8,936
14 votes
4 answers
485 views

Find a matrix whose sliding sum is the input

Given a matrix like this: 1 1 3 -2 3 -4 1 -1 1 1 1 0 0 -1 0 0 By taking a 2×2 "sliding sum", where the sum of every 2×2 region of the matrix is ...
21 votes
13 answers
2k views

Reconstruct Matrix from its diagonals

Given the diagonals of a matrix, reconstruct the original matrix. The diagonals parallel to the major diagonal (the main diagonals) will be given. Diagonals: ...
  • 5,421
15 votes
11 answers
1k views

Flood fill by distance

Say I have a grid with some obstacles: ---- | X | | | |XX | | | ---- I can fill this with numbers, as distance from the top left corner. But, because ...
  • 32.8k
23 votes
16 answers
2k views

Create Bernard from Desmos

Background In the online graphing calculator Desmos, there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed &...
  • 10.5k
5 votes
1 answer
1k views

fastest matrix multiplication on x86

This challenge requires integration with C, so you can stop reading if you're not interested. Matrix multiplication is a simple operation, but the performance depends a lot on how efficiently the code ...
  • 2,283
10 votes
15 answers
341 views

center a matrix [closed]

The words "center a" probably give flashbacks to any decent HTML developer. Luckily, we are not working with divs, we are working with matrices. Given a matrix where w=h, and given a "...
  • 691
14 votes
10 answers
1k views

Storing a band matrix

Related challenge A band matrix is a matrix whose non-zero entries fall within a diagonal band, consisting of the main diagonal and zero or more diagonals on either side of it. (The main diagonal of a ...
  • 34.6k
12 votes
10 answers
983 views

Convert J brackets back to 2-D list

Let's say we have a 2-D list, like the following one: \$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} \\ \color{blue}{5} & \color{blue}{6} & \...
  • 12.3k
13 votes
12 answers
3k views

Simulate the ripple effect

Imagine throwing a rock into a pond. You get to see perfect circles of ripples spreading out over the pond, bouncing off of each other. Of course, nothing can be as serene as that in coding, but, we ...
  • 691
40 votes
13 answers
5k views

Recreate Minecraft's lighting

Minecraft has a fairly unique lighting system. Each block's light value is either one less than the brightest one surrounding it, or it is a light source itself. Your task is to write a method that ...
  • 691
20 votes
12 answers
930 views

Convert between graph representations

What? Let's say I have this graph: 1 \ \ 2 3 \ / \ / 4 I can represent it in 2 ways: A list of connected vertices. ...
  • 1,854
12 votes
3 answers
281 views

Line Islands in a Word Search

My third word search related challenge in a row. :) Challenge: Brief explanation of what a word search is: In a word search you'll be given a grid of letters and a list of words. The idea is to cross ...
2 votes
5 answers
149 views

Generate this string table [duplicate]

For the given string s, generate generate a table like below. ...
  • 1,835
5 votes
1 answer
438 views

NxM List Combination Closest to Target

Given a list of N lists, each containing M positive integers, and a separate list of M positive integers (target values), return a list of N scalars (integers with a value of 0 or more) that ...
  • 717
3 votes
3 answers
321 views

Appease the Picky Eater

Your friend Jack is a picky eater. He only likes certain foods, and he only likes to eat a certain amount of them each day. Despite this, Jack has very strict calorie and macronutrient goals that he ...
  • 717
2 votes
2 answers
194 views

Resize the image

Given an \$n\times m\$ matrix \$A\$ and two integers \$w,h\$, output a matrix of \$w\times h\$ called \$B\$, such that $$B_{i,j} = \int_{i-1}^i\mathbb dx\int_{j-1}^j A_{\left\lceil \frac xw\cdot n\...
  • 13k
21 votes
12 answers
2k views

Bandwidth of a matrix

A band matrix is a matrix whose non-zero entries fall within a diagonal band, consisting of the main diagonal and zero or more diagonals on either side of it. (The main diagonal of a matrix consists ...
  • 34.6k
7 votes
2 answers
221 views

Count the ways to transform (2)

Your input is a matrix (2d array) of positive integers. For example: \begin{matrix} 1 & 1 & 4 & 7\\ 1 & 3 & 5 & 6\\ 2 & 1 & 4 & 5 \\ \end{matrix} A semi-continuous ...
  • 6,725
11 votes
7 answers
723 views

Knights Jam | Chess

The knight is a chess piece that, when placed on the o-marked square, can move to any of the x-marked squares (as long as they ...
  • 4,557
12 votes
5 answers
898 views

Simulating Bombs

More advanced version of this The aim of this puzzle is to simulate the impact of the shock wave of bombs on a square grid. The grid initially contains cells labelled ...
  • 4,557
22 votes
6 answers
772 views

Check if a matrix is Zarankiewicz-maximal

My final-year project at the National University of Singapore is on Zarankiewicz's problem: What is the maximum number of 1s in an \$m×n\$ binary matrix (\$m\$ rows and \$n\$ columns) with no \$a×b\$ ...
  • 1,273
20 votes
13 answers
2k views

Output the 12 Bar Blues

Note to those without experience in music: Through making an attempt to solve this problem, you may find that music and computer programming are similar in the ways that they implement rules and ...
  • 717
14 votes
14 answers
776 views

SuperSquares NxN

Given an integer N from 1-9, you must print an NxN grid of NxN boxes that print alternating 1s and Ns, with each box having an alternating starting integer. Examples ...
  • 717
7 votes
12 answers
711 views

Ragged Matrix Indexing

A ragged matrix, is a matrix that has a different number of elements in each row. Your challenge is to write a program in any favorable language to find the indices of all occurrences of target in the ...
  • 4,557
23 votes
18 answers
2k views

Print a NxN integer involute

Given an integer \$N\$, you must print a \$N\times N\$ integer involute with the numbers increasing in a clockwise rotation. You can start with either 0 or 1 at the top left, increasing as you move ...
  • 431
8 votes
8 answers
448 views

Count the ways to transform

A rigid transformation of a square array is a mapping from square arrays of a certain size to square arrays of the same size, which rearranges the elements of the array such that the distance to each ...
  • 91.5k
10 votes
7 answers
302 views

Cell Evolution Matrix

Your lab needed to simulate how a particular cell evolves over time in a 2D grid space. A sample 2D grid space below shows a single cell at the centre of the grid. ...
  • 4,557
13 votes
13 answers
2k views

Mat Printing Matrix

A manufacturing company wants to print a design on mats of varying dimensions, and they hired you to program a robot to make these mats. The design consists of alternating rings of any 2 symbols on a ...
  • 4,557
15 votes
4 answers
684 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 ...
  • 1,854
18 votes
6 answers
755 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 ...
19 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 ...
  • 101k
16 votes
10 answers
804 views

Remove submatrices

Given two integer matrices a and b, your challenge is to replace any occurences of b in <...
  • 32.8k
6 votes
1 answer
555 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 ...
  • 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\$...
20 votes
19 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 ...
  • 67.9k
24 votes
18 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 ...
  • 101k
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\$×\$...
  • 1,854
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 ...
  • 3,179
22 votes
25 answers
3k 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. ...
  • 799
18 votes
4 answers
596 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 ...
21 votes
10 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 &...
  • 67.9k
29 votes
26 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 ...
  • 67.9k
16 votes
10 answers
614 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)...
  • 22.7k
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 ...
  • 5,421
16 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: ...
  • 32.8k

1
2 3 4 5 6