Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
30 votes

Slash the matrix

MATL, 21 bytes 3XytPJ*-X*Xj~4&1ZIunq The input is a matrix with 1 for \ and ...
user avatar
  • 99.4k
29 votes

Weakened Binary Walls

MATL, 4 bytes BSXB Try it at MATL Online Explanation ...
user avatar
  • 10.6k
28 votes

Which tetromino is this?

Python 3, 124 bytes ...
user avatar
  • 65.5k
28 votes

Is there a single straight line in the matrix?

Python 2, 49 bytes Takes as input a 2D binary matrix \$ a \$, and its size \$ n \$. lambda a,n:sorted(map(sum,a+zip(*a)))[-2:]==[1,n] Try it online! There may be ...
user avatar
26 votes

Construct the Identity Matrix

MATL, 2 bytes Xy A translation of my Octave answer. Try it online. A 4 byte version with no built-ins (thanks to Luis Mendo): ...
user avatar
  • 11.1k
20 votes

Is it bipartite?

Wolfram Language (Mathematica), 26 25 bytes Tr[#//.x_:>#.#.Clip@x]<1& Try it online! How it works Given an adjacency matrix A, we find the fixed ...
user avatar
  • 5,177
19 votes

Construct the Identity Matrix

TI-BASIC, 2 bytes identity(Ans Fun fact: The shortest way to get a list {N,N} is ...
user avatar
  • 21.2k
18 votes

Construct the Identity Matrix

Julia, 9 3 bytes eye This is just a built-in function that accepts an integer n and returns an ...
user avatar
  • 24.2k
18 votes

To find islands of 1 and 0 in matrix

J, 57 bytes ,&([:(0#@-.~~.@,)](*@[*[:>./((,-)#:i.3)|.!.0])^:_ i.@$)-. Try it online! This is one of those where the idea is incredibly simple (and I ...
user avatar
  • 26.6k
17 votes

To find islands of 1 and 0 in matrix

APL (Dyalog Unicode), 29 28 bytesSBCS -1 thanks to @Adám {≢∪∨.∧⍨⍣≡2>+/↑|∘.-⍨⍸⍵}¨⊂,~∘⊂ Try it online! ⊂,~∘⊂ the matrix ...
user avatar
  • 14.5k
16 votes

Construct the Identity Matrix

APL, 5 bytes ∘.=⍨⍳ This is a monadic function train that accepts an integer on the right and returns the identity matrix. Try it here
user avatar
  • 24.2k
16 votes

ASCII texturing

APL (Dyalog Unicode), 20 12 bytesSBCS -6 bytes through dzaima Full program. Prompts stdin for: texture as a list of strings number of rows in shape matrix number of columns in shape matrix indices ...
user avatar
  • 27.1k
16 votes

Just Enough Ones

J, 41 bytes 1#.*:=1#.2>[:>@~.@,[:+&,&.>/~i.@!<@A.=@i. Try it online! A different take on brute force, which handles up to n=6 on TIO. Since the ...
user avatar
  • 26.6k
16 votes

Count my Pluses

MATL, 29 28 24 bytes z2Y6ttX*,GbZ+5Mz=z]yytvs Input is a binary matrix with 1 for '+' and <...
user avatar
  • 99.4k
14 votes

Construct the Identity Matrix

Octave, 10 4 bytes @eye Returns an anonymous function that takes a number n and returns the identity matrix.
user avatar
  • 11.1k
14 votes

Construct the Identity Matrix

Python 2, 42 bytes lambda n:zip(*[iter(([1]+[0]*n)*n)]*n)[:n] An anonymous function, produces output like ...
user avatar
  • 137k
14 votes

Decode Faux Braille

Python 3, 181 179 171 167 161 159 bytes Input by UTF-16 little-endian bytes without BOM. First decompose into columns using bit shifts, split by empty column, then hash them into a lookup table. -2 ...
user avatar
  • 2,361
14 votes

Mutually Attacking Queens

Python 2, 105 bytes lambda b:sum(b[i+d::d][:(8,7-i%8,i%8)[d%8%5]].find('1')*int(c)>0for i,c in enumerate(b)for d in[1,7,8,9]) Try it online! Explanation We ...
user avatar
  • 65.5k
13 votes
Accepted

The last stage of contamination

Since this is basically talking about a cellular automaton I give you.. Golly Quicklife rule, 10 bytes 01234/234V Input the rule, paste the grid into Golly, run ...
user avatar
13 votes

Finding Snakes in a Matrix

Python 2, 275 271 264 249 bytes Saved four bytes by replacing -1 with H and removing one slicing operation (...
user avatar
13 votes

Is there a left-right connection?

MATLAB/Octave, 115 109 98* bytes -6 bytes thanks to Luis Mendo -7 bytes thanks to Luis Mendo ...
user avatar
13 votes

Is there a single straight line in the matrix?

Brachylog, 8 bytes {z|}≡ᵛ+1 Try it online! ...
user avatar
12 votes

Construct the Identity Matrix

R, 4 bytes diag When given a matrix, diag returns the diagonal of the matrix. However, when given an integer ...
user avatar
  • 24.2k
12 votes

Decode Faux Braille

JavaScript (ES6),  148 146 143  142 bytes Saved 1 byte thanks to @ngn ...
user avatar
  • 166k
11 votes
Accepted

Find highest scoring matrix without property X

16/9 20/11 22/12 28/15 30/16 32/17 34/18 36/19 (Java) This uses a number of ideas to reduce the search space and cost. View the revision history for more details on earlier versions of the code. It'...
user avatar
  • 42.8k
11 votes

The Binary Square Diagonal Sequence

Husk, 15 14 bytes zȯḋm←CtNCİ□ṁḋN Try it online! Continually prints the results as an infinite list. Explanation I wonder whether there's a better way to get ...
user avatar
11 votes
Accepted

Where is that snake going?

Wolfram Language (Mathematica), 16+83=99 bytes Library import statement (16 bytes): <<Combinatorica` Actual function body (83 bytes): ...
user avatar
  • 16.8k
11 votes

Trim that distracting background off!

MATL, 5 bytes JYaZy Try it online! Or verify all test cases. Explanation ...
user avatar
  • 99.4k
11 votes

Calculate COVID spread

Jelly, 10 bytes ŒJạ€ŒṪ§Ṃ€Ṁ Try it online! -2 bytes thanks to Sisyphus Calculate the Manhattan differences from all 0s to all 1s, and the answer is the maximum of ...
user avatar
  • 40.2k
11 votes
Accepted

Calculate COVID spread

Stencil , 2 bytes ×v Try it online! tallies the number of necessary steps (including ...
user avatar
  • 27.1k

Only top scored, non community-wiki answers of a minimum length are eligible