Skip to content

Instantly share code, notes, and snippets.

@xpqz
Last active December 9, 2020 19:00
Show Gist options
  • Save xpqz/072cf559cfa0971d6ddf503b72775953 to your computer and use it in GitHub Desktop.
Save xpqz/072cf559cfa0971d6ddf503b72775953 to your computer and use it in GitHub Desktop.
Advent of Code 2020 Day09 Dyalog APL
DAY09←⍎¨⊃⎕NGET'data/2020/day09.txt'1
Day09←{
(i s)←⍵
r←(i-24)+⍳25 ⍝ Considered range
d←DAY09[r]+(¯1↑r)⊃DAY09 ⍝ Changed vals
n←1⌽1⊖s ⋄ n[;24]←d ⋄ n[24;]←d ⍝ Update the sums cache. Also: new←25 25↑1 1↓cache
(i+1) (n)
}
(i _)←Day09⍣{(i s)←⍺ ⋄ ~s∊⍨i⊃DAY09} 25 (∘.+⍨25↑DAY09)
idx⊃DAY09 ⍝ part 1
win←part1{⍺∊⍵+/DAY09:⍵⋄⍵+1}⍣≡⊢2
i←part1⍳⍨win+/DAY09
(⌈/+⌊/)DAY09[i+⍳win] ⍝ part2
@xpqz
Copy link
Author

xpqz commented Dec 9, 2020

The caching thing was probably not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment