From b757a941f29b49ddbd8c5c325d87d23f05588fc4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 28 Jun 2024 10:06:24 +0200 Subject: Update --- presentation.pdf | Bin 26422140 -> 41554357 bytes solution.dyalog | 31 ++++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/presentation.pdf b/presentation.pdf index d26aea2..7be01a7 100644 Binary files a/presentation.pdf and b/presentation.pdf differ diff --git a/solution.dyalog b/solution.dyalog index 7958b28..a915386 100644 --- a/solution.dyalog +++ b/solution.dyalog @@ -2,30 +2,31 @@ ]box on ⍝ Part 1 -cubes←⍎¨⊃⎕NGET'input'1 -movements←{⍵,-⍵}↓(3 3⍴4↑1) -sides←,cubes∘.+movements -≢sides~cubes +cubes←⍎¨⊃⎕NGET'../input'1 ⍝ All lava cubes +movements←{⍵,-⍵}↓(3 3⍴4↑1) ⍝ 6 possible movements each +sides←,cubes∘.+movements ⍝ Sides: Cubes added to movements +≢sides~cubes ⍝ Count of surface area ⍝ Part 2 -mins←(↑⌊/cubes)-1 1 1 -maxs←(↑⌈/cubes)+1 1 1 -in_boundary←{0≡+/((⍵maxs))} -count←0 +mins←(↑⌊/cubes)-1 1 1 ⍝ Minimum coords (minx, miny, minz) +maxs←(↑⌈/cubes)+1 1 1 ⍝ Maximum coords (maxx, maxy, maxz) +in_boundary←{0≡+/((⍵maxs))} ⍝ Is cube within boundary? +count←0 ⍝ Final count of outer surface area + cubes{ ⍝ https://dfns.dyalog.com/n_bfs.htm - 0=≢⍵:count - head←1↑⍵ ⋄ tail←1↓⍵ - neighbors←movements+¨head - next←{(in_boundary¨⍵)/⍵}neighbors - count⊢←count+(+/{(↓⍵)∊cubes}¨neighbors) - (⍺,head)∇((tail∪next)~⍺) + 0=≢⍵:count ⍝ If queue empty, return count + head←1↑⍵ ⋄ tail←1↓⍵ ⍝ head, tail of queue + neighbors←movements+¨head ⍝ 6 neighbors: head+movements + next←{(in_boundary¨⍵)/⍵}neighbors ⍝ Filter neighbors by in_boundary + count⊢←count+(+/{(↓⍵)∊cubes}¨neighbors) ⍝ Increment count with neighbors that are in cubes + (⍺,head)∇((tail∪next)~⍺) ⍝ Recursion: (visited|head) rec (tail|next)-visited }↓maxs ⍝ search visualization _←⎕ED 'grid' visualize←{ grid⊢←(maxs+1 1 1)⍴' ' - cubes{ ⍝ https://dfns.dyalog.com/n_bfs.htm + cubes{ 0=≢⍵:count head←1↑⍵ ⋄ tail←1↓⍵ grid[|head]⊢←'O' -- cgit v1.2.3