Skip to content

Instantly share code, notes, and snippets.

@xpqz
Last active December 10, 2021 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpqz/d7ffa9c4aa90a299368ffb2800f1762d to your computer and use it in GitHub Desktop.
Save xpqz/d7ffa9c4aa90a299368ffb2800f1762d to your computer and use it in GitHub Desktop.
⍝ Blatantly plagiated from @rak1507
data←↑⍎¨¨⊃⎕NGET'../d/9'1
shifts←{(⍺,2⊣/⍵)(2⊢/⍵,⍺)(2⊢⌿⍵⍪⍺)(⍺⍪2⊣⌿⍵)}
lowpoints←data<⊃⌊/10 shifts data
+/1+data[⍸lowpoints] ⍝ part 1
fill←{(×⍵)×⍵⌈⊃⌈/0 shifts ⍵}⍣≡{(2+⍳+/,⍵)@⊢⍵}9≠data
×/3↑{⍵[⍒⍵]}⊢∘≢⌸(∊fill)~0 ⍝ part 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment