adventofcode

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

commit 12d752098fda867e60bac3515df05ec5cdc38462
parent 1e0598eaf59f0e5824938fbfd436e1359e72ef26
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Fri, 10 Dec 2021 03:02:22 +0000

minor refactoring of puzzle 3

Diffstat:
M2021/puzzle_3.apl | 9++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/2021/puzzle_3.apl b/2021/puzzle_3.apl @@ -2,13 +2,12 @@ input← ⎕FIO[49] 'files/3.txt' -f← { +/(2 * ⍺) × ⍵ } a← {⍵ = '1'} ¨ input -y f x × (y← ⌽ (⍳⍴ x) - 1) f ~x← ⊃ ((≢ input) ÷ 2) < +/a ⍝ part 1 +2⊥ x × 2⊥ ~x← ⊃ ((≢ input) ÷ 2) < +/a ⍝ part 1 -m← { ⍺ ({ (⊃ ⍺ ⌷ (⊃ ((≢ ⍵ ) ÷ 2) > +/⍵ ) { (~ ⍣ ⍺) ⍵ } ¨ (⊂ ⍤1)⍉ ⊃ ⊃ ⍵ ) / ⍵ } ⍣ ((⍴ ⍵ ) > 1)) ⍵ } -n← { ⍺ ({ (⊃ ⍺ ⌷ (⊃ ((≢ ⍵ ) ÷ 2) ≤ +/⍵ ) { (~ ⍣ ⍺) ⍵ } ¨ (⊂ ⍤1)⍉ ⊃ ⊃ ⍵ ) / ⍵ } ⍣ ((⍴ ⍵ ) > 1)) ⍵ } +o← { ⍺ { (⊃ ⍺ ⌷ (⊃ ((≢ ⍵ ) ÷ 2) > +/⍵ ) { (~ ⍣ ⍺) ⍵ } ¨ (⊂ ⍤1)⍉ ⊃ ⊃ ⍵ ) / ⍵ } ⍣ ((⍴ ⍵ ) > 1) ⍵ } +c← { ⍺ { (⊃ ⍺ ⌷ (⊃ ((≢ ⍵ ) ÷ 2) ≤ +/⍵ ) { (~ ⍣ ⍺) ⍵ } ¨ (⊂ ⍤1)⍉ ⊃ ⊃ ⍵ ) / ⍵ } ⍣ ((⍴ ⍵ ) > 1) ⍵ } -(r f s ⍴ ⊃ ⊃ m/(r + 1),(⊂ a)) × (r f s ⍴ ⊃ ⊃ n/(1 + r← (⌽ (⍳s← ⍴ ↑ a) - 1)),(⊂ a)) ⍝ part 2 +(2⊥ s ⍴ ∊ o/(r + 1),⊂ a) × (2⊥ s ⍴ ∊ c/(1 + r← (⌽ (⍳s← ⍴ ↑ a) - 1)),⊂ a) ⍝ part 2 )OFF