New answers tagged

0 votes

Jelly's Untruth

HBL, 9.5 bytes '?(*(*-,. *().(0(/. 1-indexed. Try it here! Explanation The helper function on the first line takes two arguments: a list of indices and a specific ...
user avatar
  • 32.4k
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

Find the capacity of 2D printed objects

Rust, 112 bytes |l:&[u8]|{(0..).zip(l).scan(0,|a,(b,c)|{*a=(*a).max(*c);Some((*a).min(*l[b..].iter().max()?)-c)}).sum::<u8>()}; Playground Link Basically ...
user avatar
  • 483
0 votes

Check a mushroom forest

Desmos, 156 bytes ...
user avatar
  • 4,449
2 votes

Find the capacity of 2D printed objects

Haskell, 48 bytes q!u@(x:t)=q-x+maximum u`min`max q x!t q!_=q (0!) Attempt This Online!
user avatar
  • 87.8k
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.1k
3 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
1 vote

Check a mushroom forest

Jelly, 15 bytes Ḥ’R_"ƲĖS€;€"ẎQƑ A dyadic Link that accepts the widths on the left and the heights on the right and yields ...
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
  • 167k
1 vote

Flood fill by distance

Python3, 194 bytes: ...
user avatar
  • 2,976
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
  • 54k
6 votes

Flood fill by distance

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

Flood fill by distance

Retina, 121 bytes ...
user avatar
  • 144k
0 votes

Check a mushroom forest

Python 3 with NumPy, 83 bytes def f(h,w): for j in h:x,=(w*(h==j)>0).nonzero();1**((x-w[x])[1:]+1-(w[x]+x)[:-1]) Try it online! Takes two array arguments and ...
user avatar
  • 6,600
1 vote

Check a mushroom forest

BQN, 36 bytes (∨˝⍟2((∧´+´>≠⋈⌈´)¨·∾´↑¨∘↓)˘)∘⍉=⌜⟜⍷⊸× Dyadic function; takes a list of heights as its left argument and a list of widths as its right argument. ...
user avatar
  • 32.4k
1 vote

Check a mushroom forest

R, 100 bytes \(h,w,a=\(x,y,z)`if`(z>=0,complex(0,x,-z:z+y),y),p=mapply(a,h+1,seq(!h),w-1))any(table(unlist(p))>1) Attempt This Online! Complex numbers!
user avatar
  • 831
1 vote

How tall are the mushrooms?

Vyxal, 28 bytes d‹ɾ-:ż+:£₌żLÞẊ'¥¨£v"ÞfÞu;⁽G∵ Try it Online! Port of Jelly. Outputs a list of 1-indexed heights.
user avatar
  • 6,070
1 vote

Check a mushroom forest

Vyxal, 19 bytes ¨2$:NrḢ+⁰ntiv";ÞfÞu Try it online or verify all test cases. Port of 05AB1E. Too bad we don't have a loop index variable. Then it could be 16 ...
user avatar
  • 6,070
2 votes

Check a mushroom forest

Pyth, 22 21 18 bytes {Is.e,RGtr-keAb+kH Try it online! or Verify all test cases Explanation .e enumerates over the implicit ...
user avatar
  • 6,907
1 vote

Check a mushroom forest

C (clang), 128 bytes ...
user avatar
  • 18.4k
1 vote

Check a mushroom forest

Factor + math.unicode, 100 bytes ...
user avatar
  • 10.1k
3 votes

Check a mushroom forest

MathGolf, 22 bytes mÆ╤╞╡ï+m▐ò┤\h?a*^~]_▀= Port of my 05AB1E answer (the 19-bytes version; since the 22-bytes version was using a group-by, which MathGolf lacks and ...
user avatar
5 votes

Check a mushroom forest

K (ngn/k), 31 bytes {a~?a:,/x,''(!#y)+(?,/-:\!:)'y} Try it online! -4 bytes thanks to @ovs! Golfed even more with inspiration from @UnrelatedString's approach. ...
user avatar
1 vote

Check a mushroom forest

Charcoal, 26 bytes ⊙η∧ι⊙…ηκ∧λ∧⁼§θκ§θμ›⁺ιλ⊕⁻κμ Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. ...
user avatar
  • 144k
2 votes

Check a mushroom forest

JavaScript (ES6), 58 bytes Expects (heights)(widths). Returns a Boolean value. ...
user avatar
  • 167k
2 votes

Check a mushroom forest

Haskell, 112 85 75 bytes -37 bytes thanks to @Wheat Wizard's tips import Data.List f k|z<-do(i,(y,x))<-zip[0..]k;(y,)<$>[2-x+i..x+i]=z==nub z Attempt ...
user avatar
  • 1,916
2 votes

Check a mushroom forest

05AB1E, 22 19 bytes εD(Ÿ¦¨N+INèδ‚}€`DÙQ -3 bytes using a similar approach as @UnrelatedString's Python answer Input as two separated (equal-length) lists, first ...
user avatar
2 votes

Check a mushroom forest

Python, 153 105 86 bytes -19 bytes thanks to @Unrelated String lambda l:len(d:=[(h,z)for i,(h,x)in enumerate(l)for z in range(-x-~i,x+i)])==len({*d}) Attempt This Online!
user avatar
  • 1,916
1 vote

How tall are the mushrooms?

JavaScript (Node.js), 143 142 bytes ...
user avatar
  • 12.8k
3 votes

How tall are the mushrooms?

Jelly, 23 bytes Ḥ’R_"+"JJṗL;Ɱ"ẎQƑɗƇƲṀÞḢ A monadic Link that accepts a list of non-negative integers and yields a list of positive integers ...
user avatar
1 vote

Extend a matrix in all directions

Pip -xp, 20 bytes aH:PObb?fMZa[b]RL#aa Attempt This Online! Explanation Kinda ugly, too bad Pip doesn't have any way to do ...
user avatar
  • 32.4k
2 votes

How tall are the mushrooms?

Python3, 248 bytes: ...
user avatar
  • 2,976
3 votes

How tall are the mushrooms?

JavaScript (ES7),  146 131  129 bytes Saved 15 bytes thanks to @Neil! Returns a single solution as a space-separated string. ...
user avatar
  • 167k
1 vote

How tall are the mushrooms?

Clojure, 214 227 bytes ...
user avatar
  • 2,551
2 votes

How tall are the mushrooms?

Charcoal, 115 112 102 bytes ≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»≔EηL⊟ιζI§η⌕ζ⌊ζ Try it online! Link is to ...
user avatar
  • 144k
1 vote

How tall are the mushrooms?

Python, 293 264 263 262 bytes -1 bytes thanks to @Kevin Cruijssen j=lambda h:min((((n:=h.copy()).__setitem__(a+b,n.pop(a)|n.pop(b)))or j(n)for a in h for b in h if not h[a]&h[b]),default=h,key=len)...
user avatar
  • 1,916
1 vote

How tall are the mushrooms?

05AB1E, 45 43 bytes εD(Ÿ¦¨N+}[DN.Œ.Δε˜DÙQ}P}Zd#\}ε€ÅsIgݨåN*}øO Brute-force approach. Try it online or verify both test cases. Explanation: Step 1: Change each ...
user avatar
3 votes

Extend a matrix in all directions

R, 62 55 51 bytes Edit: -7 bytes thanks to Giuseppe, and -4 bytes thanks to pajonk \(a,d,`*`=array)a[t(t(which(T*d,T)-1)%%dim(a)+1)]*d Attempt This Online! R, 49 ...
user avatar
1 vote

Find the walls!

05AB1E, 26 bytes ˜s"DdiëdƶZ%2‹εZ≠i®.V"©.V˜Ï 05AB1E is very verbose with recursive approaches, and it's also not too good in most matrix-based challenges, ...
user avatar
4 votes

Find the walls!

JavaScript, 44 bytes f=a=>a.at?[a.shift(),a.pop()??a,a.map(f)]:[] ...
user avatar
  • 29.1k
4 votes

Find the walls!

Wolfram Language (Mathematica), 38 bytes MapAt[#0,#,2;;-2]~Check~#/._MapAt->{}& Try it online! Replaces non-edge elements with ...
user avatar
  • 15.8k
2 votes

Find the walls!

Retina, 84 bytes L`(?<=\[(\[(?(3)$)((])|(?<-3>\[)|\d|,)+)*)\d|\d(?=(((\[)|(?<-6>])|\d|,)+(?(6)^)])*]) Try it online! Outputs each edge element on ...
user avatar
  • 144k
2 votes

Find the walls!

BQN, 19 bytesSBCS 1¨⌾⊏⟜⍉⟜⌽⍟=⍟2∘≠˜⥊⊸/⥊  one for each ⌾⊏ of the elements of the first major ...
user avatar
  • 27.6k
7 votes

Find the walls!

Python 2, 38 bytes def f(a):a[1:-1]*=a>[f];map(f,a[1:-1]) Try it online! Expects a nested list and removes all non surface elements inplace. How? ...
user avatar
  • 6,600
5 votes

Find the walls!

J, 25 24 bytes #~&,(<:0&e.@:|"1]#:i.)@$ Try it online! Create multidimensional indices for each element using mixed base binary Mod each of those ...
user avatar
  • 27.1k
1 vote

Find the walls!

Jelly,  12  11 bytes ŒJ%þ`ṪỊ§TịF A monadic Link that accepts a rectangular multi-dimensional list and yields the elements that are on its "surface". Try ...
user avatar
3 votes

Find the walls!

R, 60 59 bytes Edit: -1 byte thanks to @Giuseppe. \(a,i=which(a|1,T))a[i[apply(i,1,\(x)!all(x-1&x-dim(a))),]] Attempt This Online!
user avatar
  • 11.5k
2 votes

Find the walls!

Factor, 73 72 83 bytes : f ( x -- ) dup real? [ drop ] [ 1 cut 1 short cut* rot append . [ f ] each ] if ; Try it online! Recursive function that (maybe) slices ...
user avatar
  • 10.1k

Top 50 recent answers are included