commit 2c600fd864a33907b1b077656c9e3a91910dd60a
parent 5313c7e007c832f1ed7cd9c82119b90ec78e915c
Author: mpizzzle <m@michaelpercival.xyz>
Date: Sat, 11 Dec 2021 00:45:50 +0000
refactoring solution 4, added test file
Diffstat:
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/2021/files/4-test.txt b/2021/files/4-test.txt
@@ -0,0 +1,19 @@
+7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
+
+22 13 17 11 0
+ 8 2 23 4 24
+21 9 14 16 7
+ 6 10 3 18 5
+ 1 12 20 15 19
+
+ 3 15 0 2 22
+ 9 18 13 17 5
+19 8 7 25 23
+20 11 10 24 4
+14 21 16 12 6
+
+14 21 17 24 4
+10 16 15 9 19
+18 8 23 26 20
+22 11 13 6 5
+ 2 0 12 3 7
diff --git a/2021/puzzle_4.apl b/2021/puzzle_4.apl
@@ -4,16 +4,15 @@ input← ⎕FIO[49] 'files/4.txt'
numbers← 1 + ⍎↑ input
table_rows← 1 + ⍎ ¨ ((⍴ s) ⍴ ⍉ ∊ { 0 < ⍴ ⍵ } ¨ s) / s← 1↓ input
-tables← {⊃ (⊂ (⍵ × 5) + ⍳5)⌷ table_rows} ¨ 1 -⍨ ⍳5 ÷⍨ ⍴ table_rows
+t← {⊃ (⊂ (⍵ × 5) + ⍳5)⌷ table_rows} ¨ 1 -⍨ ⍳5 ÷⍨ ⍴ table_rows
-p← { { (1++/+⌿⍵ - 0 >⍨ ⍵ ) × {(0 ∊ +⌿⊃ ⍵ )∨ 0 ∊ +/⊃ ⍵ } ⍵ } ¨ ⍵ }
-b← { ⊃ { ⍵ × ⍺ ≠ ⍵ }/(⌽ ⍵ ↑ numbers),⊂ tables }
-w← { ⍵ /1 t⍴ ⍳t← ≢ ⍵ }
+p← { { (1++/+⌿⍵ - 0 >⍨ ⍵ ) × {(0 ∊ +⌿⊃ ⍵ )∨ 0 ∊ +/⊃ ⍵ } ⍵ } ¨ ⍵ } ⍝ calculate winner
+b← { ⊃ { ⍵ × ⍺ ≠ ⍵ }/(⌽ ⍵ ↑ numbers),⊂ t } ⍝ calculate reduced bingo round
+w← { ⍵ /1 i⍴ ⍳i← ≢ ⍵ } ⍝ where (⍸)
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
+(1 -⍨ j⊃ a) × (numbers ⊃ ⍨ j← ↑ w a← +/¨all) - 1 ⍝ part 1
+(1 -⍨ numbers ⊃ ⍨ s) × (((1/⍨⍴ t) - 0 >⍨ p b s - 1) / (s← ↑ ⊃ w (⍴ t) = g← +/ ¨ 0 >⍨ all) ⊃ all) - 1 ⍝ part 2
)OFF