adventofcode

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

commit 5313c7e007c832f1ed7cd9c82119b90ec78e915c
parent 515bb228853d0564c5ba149313fac1fa125549b2
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Sat, 11 Dec 2021 00:31:32 +0000

puzzle 4 part 2 complete

Diffstat:
M2021/puzzle_4.apl | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/2021/puzzle_4.apl b/2021/puzzle_4.apl @@ -6,9 +6,14 @@ numbers← 1 + ⍎↑ input table_rows← 1 + ⍎ ¨ ((⍴ s) ⍴ ⍉ ∊ { 0 < ⍴ ⍵ } ¨ s) / s← 1↓ input tables← {⊃ (⊂ (⍵ × 5) + ⍳5)⌷ table_rows} ¨ 1 -⍨ ⍳5 ÷⍨ ⍴ table_rows -p← { +/{ (+/+⌿⍵ - 0 >⍨ ⍵ ) × (0 ∊ +⌿⊃ ⍵ )∨ 0 ∊ +/⊃ ⍵ } ¨ ⍵ } +p← { { (1++/+⌿⍵ - 0 >⍨ ⍵ ) × {(0 ∊ +⌿⊃ ⍵ )∨ 0 ∊ +/⊃ ⍵ } ⍵ } ¨ ⍵ } b← { ⊃ { ⍵ × ⍺ ≠ ⍵ }/(⌽ ⍵ ↑ numbers),⊂ tables } +w← { ⍵ /1 t⍴ ⍳t← ≢ ⍵ } -(i⊃ a) × ((i← ↑ { ⍵ /1 t⍴ ⍳t← ≢ ⍵ } a← {p b ⍵ } ¨ ⍳⍴ numbers > 0) ⊃ numbers) - 1 ⍝ part 1 +all← {p b ⍵ } ¨ ⍳⍴ numbers +(1 -⍨ i⊃ a) × (numbers ⊃ ⍨ i← ↑ w a← +/¨all) - 1 ⍝ part 1 + +s← ↑ ⊃ w (⍴ tables) = g← +/ ¨ 0 >⍨ all +(1 -⍨ numbers ⊃ ⍨ s) × (((1/⍨⍴ tables) - 0 >⍨ p b s - 1) / s ⊃ all) - 1 ⍝ part 2 )OFF