Browse Source

twiddling

main
rhiannon morris 10 months ago
parent
commit
f665be0180
  1. 29
      aoc.bqn

29
aoc.bqn

@ -112,30 +112,27 @@ aoc9 ⇐ { @@ -112,30 +112,27 @@ aoc9 ⇐ {
################################################################################
Fst ⇐ {0 ≡ ≠𝕩? @; ⊑𝕩}
At ⇐ {1⊑ ⊑ (⊑ ≡ 𝕩˙)¨⊸/ 𝕨} # use ⎊ for default
At ⇐ {1⊑ ⊑ (⊑ ≡ 𝕩˙)¨⊸/ 𝕨} # use ⎊ for default
aoc10 ⇐ {
BadScore1 ← ⟨')'‿3,']'‿57,'}'‿1197,'>'‿25137⟩⊸At⎊0
BadScore ← BadScore1 ∘ {'!'‿c: c; @}
BadScore1 ← ⟨')'‿3,']'‿57,'}'‿1197,'>'‿25137⟩⊸At
BadScore ← {'!'‿c: BadScore1 c; 0}
pairs ← Words "() [] {} <>"
Step ← {
'!' ≡ Fst 𝕨? 𝕨;
𝕨 𝕊 ')': '(' = Fst 𝕨? 1↓𝕨;
𝕨 𝕊 ']': '[' = Fst 𝕨? 1↓𝕨;
𝕨 𝕊 '}': '{' = Fst 𝕨? 1↓𝕨;
𝕨 𝕊 '>': '<' = Fst 𝕨? 1↓𝕨;
⊑ 𝕩∊"([{<"? 𝕩∾𝕨;
'!'‿𝕩
'!' ≡ ⊑⎊@ 𝕩? 𝕩;
𝕨 = pairs At⟜⊑⎊@ 𝕩? 1↓𝕩;
⊑ 𝕨 ∊ ⊑¨pairs? 𝕨∾𝕩;
'!'‿𝕨
}
Find ← ""⊸(Step˜´) ⌽
Find ← ""⊸(Step´) ⌽
GoodScore1 ← ⟨'('‿1,'['‿2,'{'‿3,'<'‿4⟩⊸At
GoodScoreN ← {0 ((GoodScore1 ⊣) + (5⊸× ⊢))´ 𝕩}
GoodScore ← GoodScoreN ⌽ ∘ {'!' ≡ Fst 𝕩? ""; 𝕩}
GoodScore ← {'!' ≢ ⊑𝕩? 0 ((GoodScore1 ⊣) + (5⊸× ⊢))´ ⌽ 𝕩; 0}
Middle ← ((⌊÷⟜2)∘≠ ⊑ ⊢) ∧ ∘ (0⊸≠¨⊸/)
A ⇐ +´ (BadScore∘Find¨) ∘ •FLines
B ⇐ Middle (GoodScore∘Find¨) ∘ •FLines
A ⇐ +´ BadScore∘Find¨ ∘ •FLines
B ⇐ Middle GoodScore∘Find¨ ∘ •FLines
}

Loading…
Cancel
Save