commit 725de4e726170dfaa6ce45e664d33979c760d56a parent df146d6e83e0805d18d9aae8786bae9adb56fe88 Author: mpizzzle <m@michaelpercival.xyz> Date: Wed, 2 Feb 2022 19:19:26 +0000 making solution more readable, making Dumbo a one liner Diffstat:
| M | 2021/puzzle_11.dyalog | | | 20 | +++++++++++--------- |
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/2021/puzzle_11.dyalog b/2021/puzzle_11.dyalog @@ -1,11 +1,13 @@ -test ← ⊂⍎¨10 10⍴'5483143223274585471152645561736141336146635738547841675246452176841721688288113448468485545283751526' -input ← ⊂⍎¨10 10⍴'1443582148655373485114517412468835218864166231726217316566231128178367584235166566773268437381433267' +test ← ⍎ ¨ 10 10 ⍴ '5483143223274585471152645561736141336146635738547841675246452176841721688288113448468485545283751526' +input ← ⍎ ¨ 10 10 ⍴ '1443582148655373485114517412468835218864166231726217316566231128178367584235166566773268437381433267' -b ← 9>⍨⊢ -Dumbo ← { - f ← (1 + ⊃⍵) + (((+/+⌿⍤⊢) ⌺ 3 3) ⊢)⍤b⍤⊢ - (⊂ (⊢×~⍤b⍤⊢) f ⍣ (⊢(100 = +/⍤(+⌿=⍥b)) f) 1 + ⊃⍵) , ⍺⍺ ⍵ -} +f ← 9>⍨⊢ ⍝ boolean matrix of flashes +z ← ⊢×~⍤f⍤⊢ ⍝ zero out flashes +c ← 100=+/⍤(+⌿=⍥f) ⍝ compare boolean matrices +s ← ((+/+⌿⍤⊢) ⌺ 3 3)⍤f⍤⊢ ⍝ sum stencil of flashing neighbours +g ← s+⍨1+⊃⍤⊣ ⍝ sum stencil + ⍵ + 1 -+/+⌿ ⊃ +⌿ 0 = ((⊢ Dumbo) ⍣ 100) input ⍝ part 1 -1 -⍨ 1 ↓ ((1+1↓⊢) Dumbo) ⍣ (0=(+/+⌿⍤⊃⍤⊢)) (⊃ input) 0 ⍝ part 2 +Dumbo ← { (⊂ z (⍵g⊢) ⍣ (⊢c⍵g⊢) 1 + ⊃⍵) , ⍺⍺ ⍵ } ⍝ generate next round + ++/+⌿ ⊃ +⌿ 0 = ((⊢ Dumbo) ⍣ 100) ⊂ input ⍝ part 1 +1 -⍨ 1 ↓ ((1+1↓⊢) Dumbo) ⍣ (0=(+/+⌿⍤⊃⍤⊢)) input 0 ⍝ part 2