-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday08.bqn
24 lines (22 loc) · 1.12 KB
/
day08.bqn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
⟨Split⟩←•Import"../../util/bqn_util/util.bqn"
inp←' '⊸Split¨ •FLines"../inputs/day08.txt"
# Convert instructions to BQN code: Given a list of tokens like
#
# ⟨ "d" "dec" "683" "if" "qn" "==" "0" ⟩
#
# convert them—if needed—to their respective BQN token:
#
# ⟨ "d" "-↩" "683" "×" "qn" "=" "0" ⟩
C ← {
from ← ⟨"if", "dec", "inc", ">=", "==", "<=", "!="⟩
to ← ⟨"×" , "-↩" , "+↩" , "≥" , "=" , "≤" , "≠" , ⊢⟩ # last is fallthrough
{⊑from⊐<𝕩}◶to¨𝕩
}
r ← ∊⊸/ ⊑¨inp # all registers ⇒ ⟨ "d" "rak" … ⟩
•Show •BQN ∾⟨
"h∞w←0⋄"∾∾∾⟜"←0⋄"¨r # zero everything ⇒ "h∞w←0 ⋄ d←0 ⋄ rak←0 ⋄ …"
(∾⟜"⋄"⊸∾)´({∾𝕩∾"⋄h∞w⌈↩"∾⊑𝕩}C)¨inp # Check highest after every instruction
# ⇒ "d-↩683×qn=0 ⋄ h∞w⌈↩d ⋄ d-↩-220×h=0 ⋄ h∞w⌈↩d…"
"⋄part1←⌈´"∾(∾⟜"‿"⊸∾)´r # get max ⇒ "⋄ part1 ← ⌈´d‿rak‿…"
"⋄⟨ part1, h∞w ⟩"
⟩ # ⇒ ⟨ 4416 5199 ⟩