New answers tagged

1 vote

Flood fill by distance

Julia 97 bytes h(X,r=1,c=1,d=0)=try d<X[r][c]&&(X[r][c]=d;for i=[5,7,1,3] h(X,r+i÷3-1,c+i%3-1,d+1)end)catch;end Attempt This Online! 81 bytes A greatly ...
user avatar
1 vote

Flood fill by distance

JavaScript (Node.js), 113 bytes a=>[,...0+a].map((_,i)=>a.map((r,y)=>r.map((c,x)=>r[x]=x+y?c||-~i*[2,1,0,-1].some(k=>a[y+k%2]?.[x+--k%2]==i):1))) ...
user avatar
  • 29.4k
4 votes

Flood fill by distance

Jelly, 20 19 bytes ẸŻạ§ỊẸʋƇ@ƬŒMŒṬ+C¬S: Try it online! Inspired by @Jonathan Allan's answer (it started as a golf of that answer, but portions were rewritten, and ...
1 vote

Flood fill by distance

Jelly,  25  24 bytes -1 using ais523's trick of using integer division to place inf as walls. Ø1Wạ§ỊɗƇⱮẎQɗ@ƬŒMŒṬSFṀ_Ɗ: A ...
user avatar
3 votes

Flood fill by distance

JavaScript (Node.js), 114 bytes Expects a matrix filled with \$0\$ and \$-1\$. Outputs by updating the input matrix with 1-indexed distances. ...
user avatar
  • 168k
1 vote

Flood fill by distance

Python3, 194 bytes: ...
user avatar
  • 3,046
2 votes

Flood fill by distance

Jelly, 27 bytes ŒM_Ø.ŒṬ»ḤZUµ4¡«³ FJỊṁ³ÇƬ¬S: Try it online! Input format: 0 for wall, 1 for passable cell. Output format: 0-based, walls are represented as floating-...
4 votes

Flood fill by distance

BQN, 36 34 bytesSBCS Uses for obstacles in input and output. {(𝕩⌈⊢⌊1+(«˘⌈«⌈»⌈»˘)⌾÷)⍟(≠⥊)0⌾⊑∞¨𝕩} Run online! ...
user avatar
  • 54.4k
6 votes

Flood fill by distance

J, 54 46 bytes [:(#-+/)](+[:+./(0,(,-)=0 1)|.!.0=&1)^:a:${.1: Try it online!
user avatar
  • 27.3k
3 votes

Flood fill by distance

Retina, 121 bytes ...
user avatar
  • 145k
1 vote

I transpose the source code, you transpose the input!

Vyxal, 2 bytes #∩ Try it online or try it online transposed. Receives a list of lists (a list of strings will work too). -2 bytes thanks to lyxal
user avatar
  • 6,480
1 vote

Create Bernard from Desmos

brev, 190 bytes ...
user avatar
  • 270
1 vote

Create Bernard from Desmos

BQN, 20 bytes {{⌽1¨⊸∾0¨⊸∾˘𝕩}⍟𝕩≍≍1} Try it here! Explanation Input is x. {...}⍟𝕩≍≍1 execute x times on matrix ...
user avatar
1 vote

Create Bernard from Desmos

Vyxal , 20 bytes 0?(ṘnEn›ẋJ)E1vẋ0ÞṪṘ∩ Try it Online!
user avatar
  • 6,480
1 vote

Create Bernard from Desmos

Charcoal, 26 bytes ↑1FENX²ι«‖↓UO⊗ιι1M⊕ι↑»‖UB0 Try it online! Link is to verbose version of code. Explanation: Works by drawing the horizontal mirror image of ...
user avatar
  • 145k
2 votes

Create Bernard from Desmos

Haskell, 111 bytes data T a=C a|Q(T a)(T a)(T a)(T a) f 0=C 1 f 1=Q(C 0)(C 1)(C 1)$C 1 f n=Q(C 0)(Q(C 1)(C 1)(C 0)$f$n-2)(C 1)$C 1 The matrix is represented as a ...
user avatar
  • 2,280
6 votes

Create Bernard from Desmos

Jelly, 15 bytes 2Ṛ;»Ṁ²ƊƊ¡’Bz0ZU A full program that accepts a positive integer from STDIN and prints a list representation of the Bernard. Try it online! (The ...
user avatar
6 votes

Create Bernard from Desmos

Python, 76 bytes f=lambda n:(x:=1<<n>>1)and[x*[0]+j for j in f(n-1)[::-1]]+x*[x*[1,1]]or[[1]] Attempt This Online! Straight-forward recursion. Take the previous upside down, add a block of ...
user avatar
  • 6,900
3 votes

Create Bernard from Desmos

05AB1E, 17 bytes ÎF¼RNoF¾ª]oÅ10ζRø Try it online or verify all test cases. (The footer is to pretty-print the matrix.) Explanation: Step 1: Create alternating ...
user avatar
2 votes

Create Bernard from Desmos

Python 3 with numpy, 77 76 bytes from numpy import* f=lambda n:n<eye(1)or kron(c_[:4:2,1:3],f(n-1)[::-1]+1)>1 Try it online! ...
user avatar
  • 6,406
5 votes

Create Bernard from Desmos

Factor, 90 89 83 bytes [ 2^ 3 dupn iota -rot '[ _ 3 /i bitxor bit-length 2^ 1 <array> _ 0 pad-head ] map ] Try it online! Port of @alephalpha's PARI/GP ...
user avatar
  • 10.2k
8 votes

Create Bernard from Desmos

Desmos, 94 92 bytes f(n)=[0^{0^{4^{round(u+.5log_4dd)-u}-x}}forx=L,y=L] d=3y-2^n2 u=(0^{0^d}+n)/2 L=[2^n...1]-.5 Try it on Desmos! The matrix is returned in row-...
user avatar
4 votes

Create Bernard from Desmos

Python, 121 104 bytes lambda n:[[*map(int,f"{m:0{2**n}b}")]for m in g(n)] g=lambda n:[1][n:]or g(n-1)[::-1]+2**~-n*[2**2**n-1] Attempt This Online! This is a much more interesting method, ...
user avatar
  • 1,151
2 votes

Create Bernard from Desmos

Python 3, 138 bytes import re def f(n):r=[int(bin(i)[2:])for i in range(2**n)];return[[1-bool(re.match('1(13)*(12|0)',str(x+y+y+10**n)))for x in r]for y in r] Try ...
user avatar
  • 29.4k
3 votes

Create Bernard from Desmos

JavaScript (ES6), 95 bytes A rather straightforward recursive construction. ...
user avatar
  • 168k
5 votes

Create Bernard from Desmos

PARI/GP, 52 bytes n->matrix(l=2^n,,i,j,j+2^#binary(bitxor(i-1,l\3))>l) For input \$n\$, the number of \$1\$s in the \$i\$-th row (\$1\$-index) is \$2^{\#\...
user avatar
11 votes

Create Bernard from Desmos

K (ngn/k), 21 bytes (|,/2\,'/4\10+)/[;+1] Try it online! Same algorithm, but uses a bit of base trick to generate the zero- and one-matrices at appropriate places. ...
user avatar
  • 62.8k

Top 50 recent answers are included