-
-
Save jcmorrow/0a9e1f41cd4a359e22b38678ddb6ba93 to your computer and use it in GitHub Desktop.
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
input =: ,.LF cut fread '~/code/advent_of_code/day_13.txt' | |
numline =: }. input | |
nums =: ;". &.>(-.(<,'x') = numsWithXes) # numsWithXes | |
goal =: ".;{.input | |
NB. Answer to part 1 | |
smoutput (<./ (] - |&goal) &> nums) * >(((] - |&goal) &> nums) i. (<./ (] - |&goal) &> nums)) { nums | |
inv_mod =: dyad : '(i.&1) y | x * i.y' | |
indices =: (-.(<,'x') = numsWithXes) # (i.#numsWithXes) | |
M =: */ nums | |
Ms =: M <.@% nums | |
as =: nums - nums | indices | |
ys =: ({. inv_mod "0 0 0 }.) &> (<"1 |:>Ms;nums) | |
NB. answer part 2 | |
M | +/ Ms * (as) * (ys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment