30
votes
Slash the matrix
MATL, 21 bytes
3XytPJ*-X*Xj~4&1ZIunq
The input is a matrix with 1 for \ and ...
29
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 ...
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 ...
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 ...
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 and ...
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 of ...
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 ...
16
votes
Count my Pluses
MATL, 29 28 24 bytes
z2Y6ttX*,GbZ+5Mz=z]yytvs
Input is a binary matrix with 1 for '+' and <...
15
votes
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 ...
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 ...
14
votes
13
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):
...
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
...
12
votes
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 ...
11
votes
11
votes
11
votes
Trim that distracting background off!
MATL, 5 bytes
JYaZy
Try it online! Or verify all test cases.
Explanation
...
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 ...
11
votes
Calculate COVID spread
Wolfram Language (Mathematica), 90 78 bytes
f=Length@FixedPointList[ListConvolve[CrossMatrix@1,#,{2,2},0,Times,Max]&,#]-2&
Try it online!
-12 bytes, ...
11
votes
Accepted
Calculate COVID spread
Stencil ≢, 2 bytes
×v
Try it online!
≢ tallies the number of necessary steps (including ...
11
votes
Is there a single straight line in the matrix?
Ruby, 47 bytes
->m,n{m.uniq[1]?m-[[0]*n]==[[1]*n]:m[0].sum==1}
Try it online!
Explain please:
Split the two cases:
If m has at least 2 different rows, remove ...
11
votes
Scribble Pad for Nerds
Charcoal, 9 bytes
FA✳ι##‖↘#
Try it online! Link is to verbose version of code. Explanation:
FA
Loop over the directions.
...
10
votes
Change the rules of Life
MATL, 24 23 bytes
xx:"tt3Y6Z+1Gm<8M2Gmb*+
Inputs are:
Array with birth rule
Array with survival rule
Number of generations
Matrix with initial cell ...
10
votes
Mutually Attacking Queens
JavaScript (ES7), 86 bytes
Takes input as an array of 64 integers with 254 for a queen and 0 for an empty square.
...
10
votes
Dungeon Crawler
Clean (with Snappy), 800 785 670 644 bytes
460 402 bytes of code + 360 242-byte string literal
(escaped here and on TIO because it isn't valid UTF-8)
You can verify the length of the literal here.
<...
10
votes
Is there a single straight line in the matrix?
Factor + math.unicode, 59 bytes
[ [ concat Σ = ] keep dup flip [ all-equal? ] bi@ or and ]
Try it online!
Takes \$n\$ and a ...
10
votes
Is there a single straight line in the matrix?
JavaScript (ES6), 46 bytes
Thanks to @PertinentDetail for a bug fix
Expects a multiline string with a trailing line feed. Returns a Boolean value.
...
10
votes
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
binary-matrix × 73code-golf × 65
matrix × 14
array × 11
decision-problem × 11
grid × 11
math × 6
ascii-art × 6
code-challenge × 5
number × 4
binary × 4
graph-theory × 4
string × 3
sequence × 3
game × 3
fastest-code × 3
restricted-time × 3
linear-algebra × 3
combinatorics × 2
geometry × 2
optimization × 2
open-ended-function × 2
unicode × 2
restricted-complexity × 2
kolmogorov-complexity × 1