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.
295
questions
22
votes
10
answers
2k
views
Is the group cyclic?
Introduction
You can skip this part if you already know what a cyclic group is.
A group is defined by a set and an associative binary operation \$\times\$ (that is, \$(a \times b) \times c = a \times (...
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
...
25
votes
12
answers
2k
views
Draw my Contours
Given a rectangular matrix of elevations, draw its contours.
Task
Two elements x and y are on the same contour level if ...
19
votes
23
answers
2k
views
Sum the deltas of my matrix
Background
The deltas of an array of integers is the array formed by getting the differences of consecutive elements. For example, [1, 2, 4, 7, 3, 9, 6] has the ...
7
votes
10
answers
255
views
Rotate matrix rows according to the row above
Specifications
For this challenge, you will be given a matrix of some sort in any reasonable format for a 2-D array. For each row except the last, in order from top (first) to bottom (last), rotate ...
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 ...
21
votes
18
answers
3k
views
Is this a valid Takuzu board?
Takuzu is a logic game in which you have to complete a grid with cells containing 0s and 1s. The grid must follow 3 rules:
No ...
3
votes
1
answer
155
views
Boolean Rectangles [duplicate]
Inspired by Braille graphics
Given a Boolean matrix (i.e., consisting of only 1s and 0s), output an ASCII-art-style Unicode ...
4
votes
16
answers
767
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 ...
10
votes
16
answers
1k
views
First spiral, then diagonal
Given a positive input number \$n\$, construct a spiral of numbers from \$1\$ to \$n^2\$, with \$1\$ in the top-left, spiraling inward clockwise. Take the sum of the diagonals (if \$n\$ is odd, the ...
12
votes
3
answers
608
views
Unicode rectangles
Given
a matrix a of characters from u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋"
the ...
19
votes
28
answers
1k
views
Matrix in Range
The Challenge
Given an integer n>0 output a n+1 X n+1 matrix containing all integers from ...
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.
...
11
votes
7
answers
1k
views
Simple DTMF decoding: find the phone key!
This is a simple challenge which hopefully may lead to some creative answers.
Quoting Wikipedia: "Dual-tone multi-frequency signaling (DTMF) is an in-band telecommunication signaling system using the ...
19
votes
8
answers
914
views
Optimal path through a matrix
Given a matrix consisting of positive integers, output the path with the lowest sum when traversing from the upper left element to the bottom right. You may move vertically, horizontally and ...
13
votes
8
answers
688
views
Minimal taxicab distance map
Challenge description
In taxicab metric, a distance between two points is defined as:
Consider a matrix with only zeros and ones:
...
27
votes
22
answers
6k
views
Is it a good 2048 board?
This is my first question here, so any suggestions in the comments would be appreciated! Thanks ;)
Introduction
One very common strategy for the 2048 game is never ever swiping down. This positions ...
3
votes
0
answers
584
views
Count the word from matrix [closed]
BackStory
Given a square matrix of alphabets which contain English letters in arbitrary manner. While searching a word in it, you can go left to right horizontally, vertically downwards or diagonally ...
15
votes
23
answers
846
views
Compute the Matrix-Vector
Given an integer array of at least two elements, output the Matrix-Vector (defined below) of the array.
To compute the Matrix-Vector, first rotate through the size-...
14
votes
11
answers
1k
views
2D partitioned cumulative sum
Challenge
Given a matrix M with r rows and c columns, and two Boolean lists V of length r and H of length c, calculate the partitioned cumulative vertical and horizontal sums.
Rules
r and c are ...
20
votes
15
answers
3k
views
Compress a sparse matrix
Compress a sparse matrix using Compressed sparse row (CSR, CRS or Yale format).
These are all the same form of compression (ignore new Yale).
Input may be any 2d data structure (list of lists, etc): e....
16
votes
2
answers
453
views
Show me some fireworks!
Given, in any way and order,
dimensions (in whichever order you want)
a probability (in whatever format you want)
number of iterations (you may choose whether to count the initial state or not)
do ...
25
votes
14
answers
1k
views
Pad a matrix with its sums
Challenge:
Given a square input matrix \$A\$, pad the matrix with one row and one column on all four sides.
The value of each element in the top and bottom row should be the sum of the elements in ...
22
votes
6
answers
787
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 ...
20
votes
22
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:
...
24
votes
21
answers
2k
views
Are there N consecutive occurrences of a number in a row/column in a matrix?
Take a matrix A consisting positive integers, and a single positive integer N as input, and determine if there are at least N consecutive occurrences of the same number in any row or column in the ...
28
votes
35
answers
2k
views
Index of the row with most non-zero elements
This is a simple one: Take a matrix of integers as input, and output the index of the row with the most non-zero elements. You may assume that there will only be one row with the most non-zero ...
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 ...
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 ...
27
votes
8
answers
584
views
Interlaced Rotations
Challenge
Given a square matrix of characters (single-byte printable ASCII characters), rotate each "ring" of the matrix in opposite directions.
Let's take an example:
...
10
votes
4
answers
895
views
Game of Life and Fatigue
Stewie's Game of Life and Fatigue is quite similar to the more famous Conway's Game of Life.
The universe of the Stewie's Game of Life and Fatigue (GoLF) is an infinite two-dimensional orthogonal ...
32
votes
59
answers
3k
views
Create a checkerboard matrix
Take a positive integer n as input, and output a n-by-n checkerboard matrix consisting of 1 and 0.
The top left digit should always be 1.
Test cases:
...
21
votes
6
answers
637
views
Fix my notation for lists of matrices, part 1
Sometimes, I have lists of constant matrices in my code:
[ [[1, 0],
[0, 1]],
[[1, 0],
[0,-1]],
[[0, 1],
[1, 0]],
[[0,-1],
[1, 0]] ]
That's ...
36
votes
28
answers
4k
views
Sum of first row and column, then second row and column ... and so on
Take a non-empty matrix / numeric array containing positive integers as input. Return, in this order, the sums of the first row and column, then the second row and column and continue until there aren'...
11
votes
19
answers
2k
views
Check if a matrix is a Toeplitz matrix
You will be given a two-dimensional array and a number and you are asked to find whether the given matrix is Toeplitz or not. A matrix is a Toeplitz matrix if every descending diagonal, going from ...
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 ...
20
votes
2
answers
611
views
Is magic possible?
A magic square is an n-by-n square grid, filled with distinct positive integers in the range 1,2,...n^2, such that each cell contains a different integer and the sum of the integers in each row, ...
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 ...
15
votes
9
answers
590
views
Lists and arrays, part by part
In this challenge, you'll get four different but somewhat related tasks that must be solved in a specific manner. First, I'll explain the tasks, then follows an explanation of how you must solve it.
...
14
votes
6
answers
1k
views
Evaluate a simple spreadsheet
Rules
No cell range references (A2:B3).
Maximum 9 rows and 9 columns.
No circular references or formula errors.
Empty cells evaluate to ...
22
votes
41
answers
4k
views
Robbers: Crack the regex - Make a snake
This is the robber's thread. The cop's thread is here.
A snake matrix is a square matrix that follows this pattern:
3-by-3:
1 2 3
6 5 4
7 8 9
and 4-by-4:
...
41
votes
51
answers
7k
views
Cops: Make a regex - Make a snake
This is the cop's thread. The robber's thread is here.
Write a code that takes an input n and creates a n-by-n "snake matrix".
A snake matrix is a matrix that ...
35
votes
5
answers
2k
views
Rotating a 2D Matrix
Let's say I have the following (2D) matrix:
[[1, 2, 3, 4 ],
[5, 6, 7, 8 ],
[9, 10, 11, 12],
[13, 14, 15, 16]]
Rotate the matrix counterclockwise ...
15
votes
5
answers
588
views
Find the submatrix with the smallest mean, 2.0
You're given a n-by-m matrix of integers, where n,m > 3. Your task is to find the 3-by-3 sub-matrix that has the lowest mean, and output this value.
Rules and clarifications:
The integers will be ...
22
votes
21
answers
1k
views
Find the submatrix with the smallest mean
You're given a n-by-m matrix of integers, where n,m > 3. Your task is to find the 3-by-3 sub-matrix that has the lowest mean, and output this value.
Rules and clarifications:
The integers will be ...
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 ...
16
votes
11
answers
806
views
Construct a Gaussian Matrix
Gaussian blur is a method used for blurring images smoothly. It involves creating a matrix which will be used by convolving it with the pixels of an image. In this challenge, your task is to construct ...
8
votes
4
answers
697
views
Find the rows which make each column have one True (was: Knuth's Algorithm X)
Task
Given a Boolean matrix, find one (or optionally more) subset(s) of rows which have exactly one True in each column. You may use any algorithm, but must support very large matrices, like the last ...
16
votes
20
answers
1k
views
Turn this array into a matrix
Take a non-nested array as input. Turn it into a matrix by using the following method:
Let's say my array is [1, 2, 3, 4, 5]
First, I repeat that array 5 times: (...
26
votes
19
answers
3k
views
Is it a stochastic matrix?
A stochastic matrix is a matrix of probabilities used in the context of Markov chains.
A right stochastic matrix is a matrix where each row sums to 1.
A left ...