twiddling
This commit is contained in:
parent
4682fe282f
commit
f665be0180
1 changed files with 13 additions and 16 deletions
29
aoc.bqn
29
aoc.bqn
|
@ -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…
Reference in a new issue