Last active
February 2, 2023 23:58
-
-
Save sampersand/a2ae1a4ee514dd382f6234b80417a032 to your computer and use it in GitHub Desktop.
aoc 2019 day2 part 1
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
raw =: '1,9,10,3,2,3,11,0,99,30,40,50' | |
ints =: ". every (',' cut raw) | |
run_one =: {{ | |
'op src1 src2 dst' =. (x + i.4) { y | |
select. op | |
case. 1 do. ((src1{y)+(src2{y)) dst } y | |
case. 2 do. y((src1{y)*(src2{y)) dst } y | |
case. 99 do. throw. 'oops' | |
case. do. echo 'unknown opcode: ' , ": op NB. then somehow exit | |
end. | |
pos =. pos + 4 | |
}} | |
run =: {{ | |
pos =. 0 | |
try. | |
while. 1 do. | |
y =. pos run_one y | |
pos =. pos + 4 | |
end. | |
catch. | |
end. | |
{. y | |
}} | |
run ints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment