# Questions tagged [matrix]

A matrix is a list of numbers arranged in a rectangle with rows and columns. In programming, it is also known as a 2D array. Use this tag if your challenge is about manipulating matrices.

194 questions
Filter by
Sorted by
Tagged with
466 views

### Fold up a matrix!

Given a matrix, sum its values up/down or left/right to form an X, fold it up, and return the list. I describe the algorithm here: Algorithm Your input will be a odd-sized square matrix of integers ...
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 \$ (that is, ...
1k 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 ...
1k 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 ...
1k 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 ...
234 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 ...
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 ...
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 ...
139 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 ...
640 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 ...
1k views

### First spiral, then diagonal

Given a positive input number n, construct a spiral of numbers from 1 to n^2, with ...
521 views

### Unicode rectangles

Given a matrix a of characters from u=" ╶╺╵└┕╹┖┗╴─╼┘┴┶┚┸┺╸╾━┙┵┷┛┹┻╷┌┍│├┝╿┞┡┐┬┮┤┼┾┦╀╄┑┭┯┥┽┿┩╃╇╻┎┏╽┟┢┃┠┣┒┰┲┧╁╆┨╂╊┓┱┳┪╅╈┫╉╋" the ...
1k views

### Matrix in Range

The Challenge Given an integer n>0 output a n+1 X n+1 matrix containing all integers from ...
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. ...
768 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 ...
737 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 ...
601 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: ...
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 ...
301 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 ...
752 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-...
876 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 ...
2k 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): ...
416 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 ...
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 each ...
609 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 ...
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: ...
998 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 ...
1k 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 ...
1k 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 ...
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 ...
473 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: ...
681 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 ...
2k 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: ...
608 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 a ...
2k 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'...
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. Input Format: You will be given a function which will take ...
1k 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 ...
426 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, ...
2k views

### Verify Eigenpairs

In this challenge, you will be given a square matrix A, a vector v, and a scalar λ. You will ...
555 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. ...
996 views

Rules No cell range references (A2:B3). Maximum 9 rows and 9 columns. No circular references or formula errors. Empty cells evaluate to ...
3k 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: ...
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 ...
1k 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 ...
559 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 ...
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 ...
3k 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 ...
610 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 ...