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.

100 questions
Filter by
Sorted by
Tagged with
48 votes
16 answers
6k 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 ...
• 197k
37 votes
39 answers
4k views

### Determinant of an Integer Matrix

Given a square integer matrix as input, output the determinant of the matrix. Rules You may assume that all elements in the matrix, the determinant of the matrix, and the total number of elements in ...
24 votes
26 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 ...
• 38.8k
23 votes
28 answers
2k views

### Generalized matrix trace

Inspiration. Given (by any means): A two-argument (or single argument consisting of a two-element list) black box function, f: ℤ+ × ℤ+ → ℤ+ (input and output are 1,...
• 30.4k
21 votes
18 answers
3k views

### Check if all non-zero elements in a matrix are connected

Input: A matrix containing integers in the range [0 - 9]. Challenge: Determine if all non-zero elements are connected to each other vertically and/or horizontally. Output: A truthy value if all ...
• 46.4k
20 votes
23 answers
1k views

### Simplify matrix input!

I have written a few challenges related to matrices, and common for all are that I use a format like the one below when representing the matrices, both in examples and in test cases: ...
• 46.4k
49 votes
107 answers
6k 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,395
33 votes
15 answers
4k views

### Fryer simulator

Your task is to model the effects of batter on pieces of food. Please add three layers of crust. ...
• 15.3k
24 votes
4 answers
986 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 ...
• 197k
4 votes
16 answers
783 views

### Draw diagonal positions of me squared

Based on the interpretation user @ThePirateBay made from the first version of my own challenge Output diagonal positions of me squared now I challenge you to make ASCII art that draws diagonal lines ...
• 3,416
34 votes
32 answers
5k views

### Make it explode!

Take a matrix of positive integers as input, and make it explode! The way you explode a matrix is by simply adding zeros around every element, including the outside borders. Input/output formats are ...
• 46.4k
27 votes
58 answers
3k views

### Orthodiagonal steps

It's a common problem to navigate in a 2D matrix. We've seen it many times and will see again. So let's help future us and develop the shortest solutions to generate all eight possible steps in a 2D ...
• 3,434
20 votes
13 answers
3k views

• 48.5k
30 votes
9 answers
6k views

### Calculate the permanent as quickly as possible

The challenge is to write the fastest code possible for computing the permanent of a matrix. The permanent of an n-by-n matrix ...
29 votes
9 answers
2k views

### Fire propagation simulator

Suppose we have a matrix like this: 11111 12221 12321 12221 11111 This matrix represents a terrain, and each cell represents a portion of terrain. The number in ...
• 12.9k
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 ...
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. ...
• 829
22 votes
6 answers
793 views

### Transposes and Diagonals

For this challenge, you should write a program or function which outputs the diagonals of a given square matrix. However, if you transpose the rows and columns of your solution's source code, it ...
• 197k
22 votes
28 answers
1k views

### Matrix with 1 to L(n), in all n columns

Challenge: Take a list, L containing positive integers as input: 3 5 2 1 6 and create a matrix where the n'th column contains the vector 1:L(n), where shorter ...
• 46.4k
22 votes
14 answers
2k views

### Is the matrix rank-one?

Given a matrix of integers, test if it's rank-one, meaning that every row is a multiple of the same vector. For example, in ...
• 145k
21 votes
22 answers
2k views

### Sum the diagonals

Take a matrix of positive integers as input, and output the individual sums of the elements on the diagonal lines through the matrix. You shall only count the lines that goes diagonally down and to ...
• 46.4k
21 votes
16 answers
2k views

### Verify Eigenpairs

In this challenge, you will be given a square matrix A, a vector v, and a scalar λ. You will ...
• 42.4k
21 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 ...
• 757
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 ...
• 14.1k
19 votes
5 answers
1k views

### Jordan Decomposition

Important note: Because this challenge only applies to square matrices, any time I use the term "matrix", it is assumed that I am referring to a square matrix. I am leaving off the "...
18 votes
22 answers
1k views

### Output diagonal positions of me squared

Given a number n, Output an ordered list of 1-based indices falling on either of the diagonals of an n*n square matrix. ...
• 3,416
17 votes
10 answers
539 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: <...
• 707
13 votes
9 answers
2k views

### Calculate the Kronecker Product

Related, but very different. In the examples below, $A$ and $B$ will be $2\times2$ matrices, and the matrices are one-indexed. A Kronecker product has the following properties: ...
• 46.4k
10 votes
7 answers
2k views

### There, I fixed it (with rope)

Related: Rather similar (but much easier) challenge horizontally: There I fixed it (with tape) Challenge: Given a string only containing upper- and/or lowercase letters (whichever you prefer) and new-...
• 127k
5 votes
16 answers
2k views

### 2D Array Middle Point

Given dimensions of a 2D array, except 1xn, that results in an odd number of elements, find the midpoint index. Example: Input is 3x5, representing the 2D array [0,0] [0,1] [0,2] [0,3] [0,4] [1,0] [1,...
• 479
2 votes
1 answer
226 views

### Advent Challenge 7: Balance the storage carts!

<< Prev Next >> After some careful analysis, Santa was able to determine the dock size ranges and get the presents into the correct transportation dock. Now, he needs you to help him balance ...
• 42.4k
103 votes
24 answers
18k views

### Where's the 0xBEEF?

This challenge was inspired by this Wendy's commercial from 1984. Illustration by T S Rogers Your task is to find a hexadecimal 0xBEEF on a binary bun. The 'beef' consists of the following pattern: ...
• 193k
76 votes
13 answers
4k views

### Friar simulator

The brethren from the order of St Golfus the Concise have a tradition of reciting a short prayer whenever they see someone make the sign of the cross. Due to the high level of sin measured among ...
• 15.3k
53 votes
12 answers
7k views

### Seats in a Finnish cinema

You're given the map of a cinema theatre as a boolean matrix: 0 represents a free seat, 1 - occupied. Each Finn who walks in chooses the seat farthest away (Euclidean distance) from the nearest ...
• 15.3k
38 votes
25 answers
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 ...
• 30.4k
37 votes
28 answers
4k views

27 votes
10 answers
4k views

### Symbolic matrix multiplication

There are lots of different ways to explain matrix multiplication. I'll stick with a single figure since I believe most people here are familiar with it (and the figure is very descriptive). If you ...
• 46.4k