commit 3e38183729dbe4efdc003063cc4d1c3c7d7afd23 parent 71ff6be705d7a39b749c7e2595b1d93cf229a7fe Author: mpizzzle <m@michaelpercival.xyz> Date: Thu, 9 Dec 2021 18:24:24 +0000 puzzle 3 part 2 complete (refactoring still needed) Diffstat:
| M | 2021/puzzle_3.apl | | | 14 | +++++++++++--- |
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/2021/puzzle_3.apl b/2021/puzzle_3.apl @@ -2,9 +2,17 @@ input← ⎕FIO[49] 'files/3.txt' -⍝ input← ('00100' '11110' '10110' '10111' '10101' '01111' '00111' '11100' '10000' '11001' '00010' '01010') +f← { +/(2 * ⍺) × ⍵ } +a← {⍵ = '1'} ¨ input +y f x × (y← ⌽ (⍳⍴ x) - 1) f ~x← ⊃ ((≢ input) ÷ 2) < +/a ⍝ part 1 -f← { (2 * ⍺) × ⍵ } -+/y f x × +/(y← ⌽ (⍳⍴ x) - 1) f ~x← ⊃ ((≢ input) ÷ 2) < +/{⍵ = '1'} ¨ input +m← { ⍺ ({ (⊃ ⍺ ⌷ (⊃ ((≢ ⍵ ) ÷ 2) > +/⍵ ) { (~ ⍣ ⍺) ⍵ } ¨ (⊂ ⍤1)⍉ ⊃ ⊃ ⍵ ) / ⍵ } ⍣ ((⍴ ⍵ ) > 1)) ⍵ } +n← { ⍺ ({ (⊃ ⍺ ⌷ (⊃ ((≢ ⍵ ) ÷ 2) ≤ +/⍵ ) { (~ ⍣ ⍺) ⍵ } ¨ (⊂ ⍤1)⍉ ⊃ ⊃ ⍵ ) / ⍵ } ⍣ ((⍴ ⍵ ) > 1)) ⍵ } + +s← ⍴ ↑ a +r← (⌽ (⍳s) - 1) +o← r f s ⍴ ⊃ ⊃ m/(r + 1),(⊂ a) +c← r f s ⍴ ⊃ ⊃ n/(r + 1),(⊂ a) +o × c ⍝ part 2 )OFF