Created
December 11, 2019 03:23
Advent of Code day 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in←↑⊃⎕nget '10.input' 1 ⋄ p←'#'=in | |
can_see←{⍺≡⍵:0 | |
0=+/¯1↓{p[⍵[0];⍵[1]]}¨⍺ els_btwn ⍵ } | |
els_btwn←{ ⍺≡⍵:⍬ | |
n←⍺+(⍺ slope_btwn ⍵) | |
(⊂n),(n ∇ ⍵) } | |
slope_btwn←{{⍵÷(∨/⍵)}-⍺-⍵} | |
visible_pts←{ cur←↑⍵ | |
+/{(cur can_see ↑⍵) ∧ ⍵⌷p}¨,{⍵∘.,⍵}⍳21} | |
⎕←pt1←⌈/,(21 21 ⍴(visible_pts¨,{⍵∘.,⍵}⍳21))∧p | |
⎕div←1 | |
target←11 11 ⋄ shape←21 21 | |
els←((⍳shape[0])∘.,(⍳shape[1])) | |
angles←shape ⍴{(180÷(○1))ׯ3○(÷/target slope_btwn ⍵)}¨,els | |
quad←{ r←(⍺-1)⌷1 1 0 0 ⋄ b←(⍺-1)⌷0 1 1 0 | |
rfn←(⍺-1)⌷'↓' '↓' '↑' '↑' ⋄ bfn←(⍺-1)⌷'↑' '↓' '↓' '↑' | |
(target[1]+r)(⍎rfn)[1](target[0]+b)(⍎bfn)⍵ } | |
zapped←⍬ | |
zap←{ line←↑(⍵-1)⌷(0,target[1]) (target[0],shape[1]-1) ((shape[0]-1),target[1]) (target[0],0) | |
zapped,←{ 0<+/p[⍵]:1↑p[⍵]/⍵ | |
⍬ }(target els_btwn line) | |
zapped,←{({(target can_see ⍵)∧(⍵⌷p)}¨⍵)/⍵}(, ⍵ quad els)[⍋, ⍵ quad angles] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment