Skip to content

Instantly share code, notes, and snippets.

@jcmorrow
Created December 13, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcmorrow/0a9e1f41cd4a359e22b38678ddb6ba93 to your computer and use it in GitHub Desktop.
Save jcmorrow/0a9e1f41cd4a359e22b38678ddb6ba93 to your computer and use it in GitHub Desktop.
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