advent-of-code/2023/day22/day22.bqn
2024-11-12 21:46:18 +01:00

23 lines
942 B
BQN
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Split•Import"../bqn-libs/strings.bqn"
bricks(2¨˝¨)>¨•ParseFloat¨¨¨","Split¨¨"~"Split¨•FLines"test"
xmaxymaxzmax1+˝´bricks
hxmaxymax0
segs{(𝕩)+¨1+-˜˝𝕩}¨2˘¨bricks
zs1+2¨(˝-˝)¨bricks
h{segszs𝕊𝕩: zs+(segs)𝕩}´segs¨zs
Covered´(2˘(1))
es¯2¨¨2¨¨/¨{Covered𝕩¨bricks}¨xmaxymax
a1˙¨(es)(˜bricks)0
Fall{𝕊bricks:
newz{1+0´𝕩/2¨˝¨bricks}¨<˘a
{𝕩+newz-2¨˝¨bricks}(2˘¨)bricks
}
#fallenbricks←Fall⍟zmax bricks
fallenbricksFall{𝕊𝔽𝕩} bricks
es2{1=|-´2¨˝,˝{𝕎𝕩}¨𝕩fallenbricks}¨/es
b1˙¨(es2)(˜bricks)0
+´0=+˝(1+˝b)/b