commit a62f6ffa9769f78206c09c59f942daec20c91f73
parent effce69a0ba285e2901cec1dd0a7f12b99d55530
Author: mpizzzle <m@michaelpercival.xyz>
Date: Fri, 17 Dec 2021 21:58:14 +0000
minor formatting of puzzle 14
Diffstat:
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/2021/puzzle_14.apl b/2021/puzzle_14.apl
@@ -2,13 +2,11 @@
input← ⎕FIO[49] 'files/14.txt'
-pad← {(1 -⍨ 2 × ⍴ ⍵) ⍴ ∊⍵,¨' '/⍨⍴⍵}
-r← {((↑↑⍵),' ',↑⌽↑⍵) (↑⌽⍵)} ¨ {⍵⊂⍨~⍵∊'-> '} ¨ 2 ↓ input
-s←{∊ a ({((3-⍨⍴y)↑y),,/(3-⍨⍴y)↓y←1⌽(⊂1⍴⍺),⍨¯1⌽⍵} ⍣ d) (1↓(d←(' '≠a←↑⌽⍺)×+/⍵ ⍷⍨ ↑⍺),⍵⊂⍨~¯1⌽⍵ ⍷⍨ ↑⍺)}
-c←({s/r, ⊂ pad ⊃ ⍵} ⍣ 10) 1 ⌷ input
+pad← {⊂(1 -⍨ 2 × ⍴ ⍵) ⍴ ∊⍵,¨' '/⍨⍴⍵} ⍝ insert space between every char in string
+rules← {((↑↑⍵),' ',↑⌽↑⍵) (↑⌽⍵)} ¨ {⍵⊂⍨~⍵∊'-> '} ¨ 2 ↓ input ⍝ formatted rules
+insert← {∊ a ({(k↑y),,/(k←3-⍨⍴y)↓y←1⌽(⊂1⍴⍺),⍨¯1⌽⍵} ⍣ d) (1↓(d←(' '≠a←↑⌽⍺)×+/⍵ ⍷⍨ ↑⍺),⍵⊂⍨~¯1⌽⍵ ⍷⍨ ↑⍺)} ⍝ apply rule
-(↑⌽f)-⍨↑f←o/⍨0≠o←l[⍒l←{+/+⌿⍵} ¨ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ∘.= c] ⍝ part 1
+q←{+/+⌿⍵} ¨ ⎕AV[65+⍳26] ∘.= ({insert / rules,pad ⊃ ⍵} ⍣ 10) 1 ⌷ input ⍝ find quantities
+(↑f) - ↑⌽f← o /⍨ 0 ≠ o←q[⍒ q] ⍝ part 1
)OFF
-
-