Skip to content

Instantly share code, notes, and snippets.

@codesections
Last active December 3, 2019 02:30
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 codesections/0579ee8377784826644d18d19c2f0bbf to your computer and use it in GitHub Desktop.
Save codesections/0579ee8377784826644d18d19c2f0bbf to your computer and use it in GitHub Desktop.
Advent of Code day 2
⎕IO←0
find←{
⍺←0
in←(⊃⍺⌷,(⍳100)∘.,⍳100) set ⊃0⌷⍵
(⊃1⌷⍵)=0⌷intcode in:in[1 2]
(⍺+1)∇in (⊃1⌷⍵)
}
set←{s←⍵ ⋄ s[1 2]←⍺[0 1] ⋄ s}
intcode←{
⍺←0 ⋄ s←state←⍵
(a b c)←in[⍺+1],in[⍺+2],in[⍺+3]
⍺≥0⌷⍴⍵:'ERR: no HALT opcode'
1=⍺⌷⍵:⍺{s[c]←⍵[a]+⍵[b] ⋄ (⍺+4)intcode s}⍵
2=⍺⌷⍵:⍺{s[c]←⍵[a]×⍵[b] ⋄ (⍺+4)intcode s}⍵
99=⍺⌷⍵:,⍵
'ERR: Unknown opcode'
}
in←⍎¨','(≠⊆⊢) ⊃⊃⎕nget '02.input' 1
pt1←0⌷intcode 12 2 set in
pt2←find in 19690720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment