Last active
December 9, 2020 19:00
-
-
Save xpqz/072cf559cfa0971d6ddf503b72775953 to your computer and use it in GitHub Desktop.
Advent of Code 2020 Day09 Dyalog APL
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The caching thing was probably not worth it.