Skip to content

Instantly share code, notes, and snippets.

@tommyip
Created December 28, 2020 04:35
Show Gist options
  • Save tommyip/2edf7f8a317f670667b0ec6f1330555b to your computer and use it in GitHub Desktop.
Save tommyip/2edf7f8a317f670667b0ec6f1330555b to your computer and use it in GitHub Desktop.
AoC2020 Day 13 Dyalog APL solution from @jayfoad
⍝ Credit: @jayfoad (https://github.com/jayfoad/aoc2020apl/blob/main/p13.dyalog)
⎕IO←0
a←⍎⊃p←⊃⎕NGET'p13.txt'1
d←⍎¨b⌷⍨⊂c←⍸(,'x')∘≢¨b←'\w+'⎕S'&'⊃⌽p
{(⊃⍋⍵)⊃d×⍵}d|-a ⍝ part 1
⎕PP←17 ⋄ ⎕FR←1287
gcd←{⍵=0:⍺ 1 0 ⋄ g s t←⍵∇⍵|⍺ ⋄ g t(s-t×⌊⍺÷⍵)}
crt←{z←⍵÷⍨m←×/⍵ ⋄ m|+/⍺×z×1⊃¨z gcd¨⍵}
(-c)crt d ⍝ part 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment