Last active
December 6, 2022 19:15
-
-
Save RocketRace/93c65f5eb7e2b15986628a26c0717a2f to your computer and use it in GitHub Desktop.
Showing off my 2022 Advent of Code submissions written using Dyalog APL. Not all days will necessarily be implemented.
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
⎕IO ← 0 | |
⍝ Day 1 | |
⍝ Input: a nested vector of numbers | |
d1p1 ← ⌈/+/¨ | |
d1p2 ← {+/ 3↑ {⍵[⍒⍵]} +/¨⍵} | |
⍝ Day 2 | |
⍝ Input: a `n 2`-shaped character matrix | |
d2p1a ← {+/ 1 {⍵ + 1 + 3 × 3 | 1 + ⍵ - ⍺}¨ ⍥ ((⍉ (3∘| 'ABCXYZ'∘⍳)¨ ⍵)∘(↑⍨)) ¯1} | |
d2p2a ← {+/ 1 {(3 × ⍵) + 1 + 3 | ⍵ + ⍺ - 1}¨ ⍥ ((⍉ (3∘| 'ABCXYZ'∘⍳)¨ ⍵)∘(↑⍨)) ¯1} | |
⍝ Alternate input: two equal-length character vectors | |
d2p1b ← (+/ {⍵ + 1 + 3 × 3 | 1 + ⍵ - ⍺}¨ ⍥ (3∘| 'ABCXYZ'∘⍳)¨) | |
d2p2b ← (+/ {(3 × ⍵) + 1 + 3 | ⍵ + ⍺ - 1}¨ ⍥ (3∘| 'ABCXYZ'∘⍳)¨) | |
⍝ Day 3 | |
⍝ Input: A vector of strings, one string per compartment | |
d3p1 ← {(2∘⍟ 2∘⊥)¨ ∧/ ({2,⍨(≢⍵)÷2} ⍴ ⊢) {∨/ (64⍴2)⊤ 2* 1+ ((¯1∘⎕C ⎕A),⎕A)⍳⍵}¨ ⍵} | |
d3p2 ← {(2∘⍟ 2∘⊥)¨ ∧/ ({6,⍨(≢⍵)÷6} ⍴ ⊢) {∨/ (64⍴2)⊤ 2* 1+ ((¯1∘⎕C ⎕A),⎕A)⍳⍵}¨ ⍵} | |
⍝ Day 6 | |
⍝ Input: A string as the right argument, and a window size as the left argument | |
⍝ (4 for part a, 14 for part 2) | |
d6 ← {⍺ + ⍺ ⍳⍨ ≢¨ ⍺∪/ ⍵} | |
d6t ← ⊣+(≢¨∪/)⍳⊣ ⍝ (tacit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment