diff options
author | Marvin Borner | 2024-06-28 10:06:24 +0200 |
---|---|---|
committer | Marvin Borner | 2024-06-28 10:06:24 +0200 |
commit | b757a941f29b49ddbd8c5c325d87d23f05588fc4 (patch) | |
tree | 7a7659d037d3e3ccb5d8ab7a19a5778e645176f3 | |
parent | 8b9f68dc46ba619a94686002805766618f214e5a (diff) |
Update
-rw-r--r-- | presentation.pdf | bin | 26422140 -> 41554357 bytes | |||
-rw-r--r-- | solution.dyalog | 31 |
2 files changed, 16 insertions, 15 deletions
diff --git a/presentation.pdf b/presentation.pdf Binary files differindex d26aea2..7be01a7 100644 --- a/presentation.pdf +++ b/presentation.pdf 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≡+/((⍵<mins),(⍵>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≡+/((⍵<mins),(⍵>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' |