Created
December 28, 2020 04:35
-
-
Save tommyip/2edf7f8a317f670667b0ec6f1330555b to your computer and use it in GitHub Desktop.
AoC2020 Day 13 Dyalog APL solution from @jayfoad
This file contains hidden or 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
⍝ 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