Skip to content

Instantly share code, notes, and snippets.

@jcmorrow

jcmorrow/day_13.ijs Secret

Created Dec 13, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.