tvl-depot/users/sterni/exercises/aoc/2022/17/17.bqn

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.5 KiB
BQN
Raw Normal View History

jets '>'= "<>" (˜/) •FChars "input"
pieces >¨1111010,111,010001,001,1111,1,1,111,11
w 7
initial 0w0
# Warning: mutated global!
ji 0
_try {( 𝕩˙((+´𝕨)) 𝔽) 𝕩}
Fall {
pushed 𝕨 ((jijets)«»)˘ _try 𝕩
ji (jets)|ji+1
fallen 𝕨 » _try pushed
𝕨 𝕊(pushedfallen) fallen
}
Height (´˘/)
ThrowPiece {
piece 𝕩 (|˜) pieces
chamber (((3+piece)+(1)(1+)/´˘))𝕨
falling (chamber)(»2 w)˘piece
chamber (Fall) falling
}
•Out "day17.1: "•Fmt Height initial ThrowPiece˜´ 2022
# https://mlochbaum.github.io/BQN/doc/control.html#while
While {𝕩{𝔽𝔾𝔽_𝕣_𝔾𝔽𝔾𝕩}𝕨@}´
{
target 1000000000000
ji 0 i 0 res @
chamber initial
cycles pieces,jets<
While {𝕤res=@}{𝕤
chamber chamber ThrowPiece i
i + 1
t i|˜pieces
cycles {
new 𝕩<iHeight chamber
res {𝕊 𝕩:
pl,hl· chk ¯2new
pdhd -´chk
@˙(0pd|target-pl) hl+hd×pd÷˜target-pl
}(1<new) @
new
}(tji) cycles
}
•Out "day17.2: "•Fmt res
}