adventofcode

https://adventofcode.com/
Log | Files | Refs

commit 6275d4357af09477ffb97b2f950dc526cd393f38
parent d434483f53e9a0b0976f04feb27716088ef978ef
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Mon, 13 Dec 2021 21:35:52 +0000

puzzle 10 part 2 complete

Diffstat:
M2021/puzzle_10.apl | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/2021/puzzle_10.apl b/2021/puzzle_10.apl @@ -2,10 +2,16 @@ input← ⎕FIO[49] 'files/10.txt' -g← {(2|⍳2×⍴⍵ )⊂ 2/⍵ }¨input -a← +⌿+/(3×g=')') (¯3×g='(') (57×g=']') (¯57×g='[') (1197×g='}') (¯1197×g='{') (25137×g='>') (¯25137×g='<') +p← {(2|⍳2×⍴⍵ )⊂ 2/⍵ }¨input ⍝ partition chars +s← +⌿+/(3×p=')') (¯3×p='(') (57×p=']') (¯57×p='[') (1197×p='}') (¯1197×p='{') (25137×p='>') (¯25137×p='<') ⍝ map scores +f← {(2⌷⍴ b)⍴ b← ⍉ ⊃ ⍵ } ¨ ⊃ s ⍝ formatting -r← {⍵ /⍨ 1,2 = 2+/ 0≠1,⍨2 {(~q) + (⍺+⍵ ) × q← ⍺ < ⍵ } / ⍵ } -+/{↑ (0 >⍨ t) / t← (r ⍣ {(⍴ ⍺) = ⍴ ⍵ }) ⍵ } ¨ {(2⌷⍴ b)⍴ b← ⍉ ⊃ ⍵ } ¨ ⊃ a ⍝ part 1 +r← {⍵ /⍨0≠(w,1)×1,w← 2{(~q)+(⍺+⍵ )×q← ⍺<⍵ }/⍵ } ⍝ reduce connected chunks +m← {(r ⍣ {(⍴ ⍺) = ⍴ ⍵ }) ⍵ } ¨ f ⍝ do r until all chunks reduced + ++/{↑ (0 >⍨ ⍵ ) / ⍵ } ¨ m ⍝ part 1 + +i← ⌽ ¨m/⍨ 0=+/⊃ 0>⍨m ⍝ find all lines with incomplete chunks +y[⍋ y] ⌷⍨ ⌈2÷⍨⍴ y← {{⍺+5×⍵ }/0,⍨⍵ }¨⌽ ¨(1ׯ3=i)+(2ׯ57=i)+(3ׯ1197=i)+(4ׯ25137=i) ⍝ part 2 )OFF