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 ⇐ {
|
aoc10 ⇐ {
|
||||||
BadScore1 ← ⟨')'‿3,']'‿57,'}'‿1197,'>'‿25137⟩⊸At⎊0
|
BadScore1 ← ⟨')'‿3,']'‿57,'}'‿1197,'>'‿25137⟩⊸At
|
||||||
BadScore ← BadScore1 ∘ {'!'‿c: c; @}
|
BadScore ← {'!'‿c: BadScore1 c; 0}
|
||||||
|
|
||||||
|
pairs ← Words "() [] {} <>"
|
||||||
|
|
||||||
Step ← {
|
Step ← {
|
||||||
'!' ≡ Fst 𝕨? 𝕨;
|
'!' ≡ ⊑⎊@ 𝕩? 𝕩;
|
||||||
𝕨 𝕊 ')': '(' = Fst 𝕨? 1↓𝕨;
|
𝕨 = pairs At⟜⊑⎊@ 𝕩? 1↓𝕩;
|
||||||
𝕨 𝕊 ']': '[' = Fst 𝕨? 1↓𝕨;
|
⊑ 𝕨 ∊ ⊑¨pairs? 𝕨∾𝕩;
|
||||||
𝕨 𝕊 '}': '{' = Fst 𝕨? 1↓𝕨;
|
'!'‿𝕨
|
||||||
𝕨 𝕊 '>': '<' = Fst 𝕨? 1↓𝕨;
|
|
||||||
⊑ 𝕩∊"([{<"? 𝕩∾𝕨;
|
|
||||||
'!'‿𝕩
|
|
||||||
}
|
}
|
||||||
Find ← ""⊸(Step˜´) ⌽
|
Find ← ""⊸(Step´) ⌽
|
||||||
|
|
||||||
GoodScore1 ← ⟨'('‿1,'['‿2,'{'‿3,'<'‿4⟩⊸At
|
GoodScore1 ← ⟨'('‿1,'['‿2,'{'‿3,'<'‿4⟩⊸At
|
||||||
GoodScoreN ← {0 ((GoodScore1 ⊣) + (5⊸× ⊢))´ 𝕩}
|
GoodScore ← {'!' ≢ ⊑𝕩? 0 ((GoodScore1 ⊣) + (5⊸× ⊢))´ ⌽ 𝕩; 0}
|
||||||
GoodScore ← GoodScoreN ⌽ ∘ {'!' ≡ Fst 𝕩? ""; 𝕩}
|
|
||||||
|
|
||||||
Middle ← ((⌊÷⟜2)∘≠ ⊑ ⊢) ∧ ∘ (0⊸≠¨⊸/)
|
Middle ← ((⌊÷⟜2)∘≠ ⊑ ⊢) ∧ ∘ (0⊸≠¨⊸/)
|
||||||
|
|
||||||
A ⇐ +´ (BadScore∘Find¨) ∘ •FLines
|
A ⇐ +´ BadScore∘Find¨ ∘ •FLines
|
||||||
B ⇐ Middle (GoodScore∘Find¨) ∘ •FLines
|
B ⇐ Middle GoodScore∘Find¨ ∘ •FLines
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue