Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [binary-matrix]

Indicates that the challenge involves the manipulation of binary matrices, matrices whose elements are all one of two possible values, typically 1 and 0, or True and False.

Filter by
Sorted by
Tagged with
4 votes
4 answers
640 views

Consider an n by n binary matrix. If it has rank r <= n, then we want to compute the largest number bits flips necessary to reduce its rank to a specific value. All computations should be done ...
Simd's user avatar
  • 3,167
3 votes
4 answers
607 views

There are 251610 6 by 6 binary matrices that are inequivalent. We say two matrices are equivalent if there is some permutation of their rows and/or columns that makes them equal. For example: ...
Simd's user avatar
  • 3,167
14 votes
18 answers
2k views

In the classic game of Sokoban the player's character solves puzzles by pushing boxes around a warehouse onto designated targets. Take, for example, this ASCIIfied game level: ...
Jordan's user avatar
  • 11.9k
14 votes
5 answers
747 views

Output a grid of characters visualizing the decomposition of a number into a sum of four perfect squares. Challenge Given a nonnegative integer \$0 \le n \le 2^{30}\$, output a \$2^k \times 2^k\$ ...
bb94's user avatar
  • 3,898
1 vote
3 answers
342 views

I want an n*n table that is filled with black or white and the following conditions are satisfied in it: All cells of a 2*2 square in this table should not be the same color. All black and white ...
Shahnazi2002's user avatar
16 votes
7 answers
1k views

Take the sequence of all natural numbers in binary, (1, 10, 11, ..) then write them vertically beside each-other like this (least significant bit on top; 0s have ...
mousetail's user avatar
  • 14.4k
12 votes
11 answers
837 views

You are given a matrix of size m x n where each cell can contain either 1 or 0. You need to find the largest square submatrix that contains only 1's. The output should be the area of the largest ...
user avatar
16 votes
12 answers
2k views

A Shift matrix is a binary matrix with one superdiagonal or subdiagonal formed by only ones, everything else is a zero. A superdiagonal/subdiagonal is a diagonal parallel to the main diagonal, which ...
math scat's user avatar
  • 9,528
13 votes
8 answers
1k views

Inspired by the title of the Toggle some bits and get a square challenge. In that challenge you output how many bits should be toggled, in order for the base-10 representation of the binary to become ...
Kevin Cruijssen's user avatar
11 votes
14 answers
2k views

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. It's time to prepare an advent calendar, but I've only got a large sheet of rectangular paper, randomly colored red ...
Bubbler's user avatar
  • 79.3k
15 votes
14 answers
2k views

Inspiration There is a problem on the most recent AMC 12B test, the one held on November 16, 2022, which goes like this: (AMC 12B 2022, Question 17) How many \$4\times4\$ arrays whose entries are \$0\...
Aiden Chow's user avatar
  • 14.5k
21 votes
6 answers
2k views

A Young diagram is a rectangular binary mask whose every row and every column are sorted in descending order. It is easy to check that every rectangular binary mask can be formed by xor-ing together a ...
loopy walt's user avatar
  • 16.9k
23 votes
6 answers
1k views

Find the max number of Xs you can fit onto a rectangular tic-tac-toe board of length l and height h without ever having 3 consecutive Xs in a row diagonally, horizontally, or vertically. This is a ...
JohnBGoode's user avatar
18 votes
8 answers
3k views

aka. implement an easier version of 05ab1e's canvas element. Description The canvas element is used to draw ASCII lines on the screen. The (easier version of the) canvas element takes a list of ...
math scat's user avatar
  • 9,528
19 votes
7 answers
2k views

A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is 0. For example, the array ...
Number Basher's user avatar
14 votes
7 answers
1k views

A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is <...
alephalpha's user avatar
  • 51.9k
21 votes
9 answers
1k views

Input An \$m\$ by \$n\$ binary matrix, with \$m\$ and \$n\$ both at least 2. Think of the ones as gobs of melted cheese, which stretch as we expand the matrix horizontally and vertically. More ...
Jonah's user avatar
  • 34.1k
6 votes
2 answers
489 views

Black Box is a board game, Your task is to reveal all clues of that game. What is black box Black box is a board game with hidden atoms, Your task is given input with atoms, reveal all clues. The ...
Fmbalbuena's user avatar
  • 5,085
22 votes
6 answers
884 views

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\$ ...
Parcly Taxel's user avatar
  • 4,749
18 votes
20 answers
2k views

Inspired by this Mathematica.SE post Given two positive integers \$n, k\$ with \$n > k \ge 1\$, output a binary \$n\times n\$ matrix such that every row and column contains exactly \$k\$ 1s, and ...
caird coinheringaahing's user avatar
12 votes
9 answers
1k views

Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2017 Day 14. To recap: The disk is a rectangular grid with \$r\$ rows and \$c\$ columns. Each ...
Bubbler's user avatar
  • 79.3k
20 votes
13 answers
2k views

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 ...
Luis Mendo's user avatar
  • 107k
9 votes
9 answers
1k views

Consider the following 9 "row patterns", using 0s to represent empty cells and 1s to represent a full cell. Each pattern is associated with an integer \$n\$, such that \$0 \le n \le 8\$ (...
l4m2's user avatar
  • 32.4k
9 votes
3 answers
391 views

Much harder than Can this pattern be made with dominoes? Challenge A grid of width \$w\$ and height \$h\$ is given, filled with 1s and 0s. You can place a domino somewhere on the grid only if both ...
Bubbler's user avatar
  • 79.3k
8 votes
6 answers
603 views

Consider the following binary matrix: $$\begin{matrix} 1 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 1 \end{matrix}$$ The (1-indexed) co-ordinates of the \$1\$s here are \$(1,1), (1,3), (2,...
caird coinheringaahing's user avatar
13 votes
11 answers
2k views

As some of you may remember, Peter, who was a picky eater is now puzzled Peter. This time Peter got some puzzles as a present from his Aunt. He has tried a lot, but has failed to solve the puzzles. ...
user avatar
18 votes
11 answers
2k views

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 ...
math scat's user avatar
  • 9,528
10 votes
4 answers
347 views

Given a positive integer \$n\$, output \$n\$ 2D bool images with the same width and height such that: Each image should be 4-connected, i.e. for each two pixels that are true, you can start from one ...
l4m2's user avatar
  • 32.4k
34 votes
26 answers
4k views

Inspired by Wzl Determine if a given square binary matrix has exactly one row or column consisting of entirely 1s, and the rest of the matrix is ...
caird coinheringaahing's user avatar
20 votes
16 answers
2k views

Task Given a square array of 0s and 1s, determine whether or not there exists a path of 1s connecting the leftmost and rightmost columns. A path can take steps of one unit up, down, left or right, ...
aeh5040's user avatar
  • 2,072
13 votes
2 answers
399 views

Sandbox Given a boolean matrix representing my grass field, sheep length \$n\$ and wool thickness \$k\$, you will have to count my sheep. A sheep is a single independent unbroken line of sheep length \...
Razetime's user avatar
  • 27.6k
18 votes
9 answers
2k views

But Is It Art? is an esolang created by ais523, where one step is break the program into orthogonally connected "tiles": A BBBB A B B AA CC A CC Each ...
caird coinheringaahing's user avatar
24 votes
19 answers
2k views

Challenge Given a positive integer \$n\$, count the number of \$n\times n\$ binary matrices (i.e. whose entries are \$0\$ or \$1\$) with exactly two \$1\$'s in each rows and two \$1\$'s in each column....
Delfad0r's user avatar
  • 6,276
25 votes
15 answers
4k views

Background An L-shape is defined as a polyomino which can be made by extending two rectangular legs in orthogonal directions from a full square (called a pivot). The size of the square should be at ...
Bubbler's user avatar
  • 79.3k
16 votes
18 answers
3k views

Because the coronavirus is still at large, I thought it would be fitting to have a epidemic-themed challenge. Challenge You are given a 2D array of people, where 1 ...
applemonkey496's user avatar
18 votes
6 answers
501 views

Background Tetris Grand Master 3 has a hidden grading system based on the shape of the stack at the end of the game, which is called Secret ">" Stacking Challenge. It consists of entirely ...
Bubbler's user avatar
  • 79.3k
24 votes
9 answers
963 views

Write a program that takes in two non-negative integers S and N in that order. S represents the side length of a square grid of . characters. N represents the ...
Calvin's Hobbies's user avatar
25 votes
14 answers
3k views

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 ...
AZTECCO's user avatar
  • 11k
32 votes
6 answers
2k views

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 ...
ngn's user avatar
  • 15.6k
9 votes
3 answers
459 views

You’re given two \$r×c\$ grids. Each cell contains either 0 or 1. What are the minimum number of swaps (between horizontally and vertically adjacent cell elements, no wrapping i.e no swapping between ...
Kiara Dan's user avatar
  • 221
33 votes
18 answers
8k views

Given a two dimensional matrix of 0 and 1s. Find the number of island for 1s and 0s where neighbours are only in the horizontal and vertical. ...
KB joy's user avatar
  • 339
40 votes
4 answers
2k views

Input A binary matrix \$M\$ representing the walls of a dungeon. The position \$(x,y)\$ of the player within the dungeon. The direction \$d\$ that the player is currently facing (0 = North, 1 = East, ...
Arnauld's user avatar
  • 206k
13 votes
16 answers
2k views

Isn't it annoying when you're taking a picture, but the background detracts from the actual substance of the image? I'd say it is. I need to know how much I should crop so that I get rid of this ...
Mr. Xcoder's user avatar
  • 42.9k
8 votes
15 answers
1k views

Inspired and looted from this dice challenge by Arnauld Input You are given a 5x1 or 1x5 (your choice) dice matrix which consist of binary 3x3 sub-matrices. Goal Given a valid dice matrix, you are ...
Veskah's user avatar
  • 4,130
21 votes
8 answers
2k views

We've got quite a few national flag challenges already: AU CH FI FR GB GB IS KR NP US... Here's another, somewhat more advanced one: Return or print the decorative pattern from Belarus's national ...
ngn's user avatar
  • 15.6k
22 votes
10 answers
2k views

Input A non-empty binary matrix consisting of 3x3 sub-matrices put side by side. Task Your task is to identify valid dice patterns (as described below) among the 3x3 sub-matrices. Each valid ...
Arnauld's user avatar
  • 206k
40 votes
10 answers
3k views

Write a function (using as few bytes as possible) that takes a bi-dimensional array of any number of columns and rows in which: 0 represents empty block, ...
Adelin's user avatar
  • 443
26 votes
8 answers
2k views

Let an 8x8 chessboard be represented by any two distinct values, with one value being an empty square and the other being a queen. In the following examples, I use 0s as the empty squares and 1s as ...
JMigst's user avatar
  • 879
11 votes
3 answers
514 views

Input: A 2D array containing two distinct (optional) values. I'll use 0 and 1 when explaining the rules. The input format is of course flexible. Challenge: Zeros are water, and ones are islands. In ...
Stewie Griffin's user avatar
15 votes
9 answers
684 views

A maze is given as a matrix of 0s (walls) and 1s (walkable space) in any convenient format. Each cell is considered connected to its 4 (or fewer) orthogonal neighbours. A connected component is a set ...
ngn's user avatar
  • 15.6k