From a46f56da7f66d9eb61c6bae523c6624ccbeaebea Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 5 Dec 2019 22:45:18 +0000 Subject: [PATCH] Implement opcodes 3 and 4, naively --- lib/intcode/intcode.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/intcode/intcode.zig b/lib/intcode/intcode.zig index 062bdaa..fe9b82b 100644 --- a/lib/intcode/intcode.zig +++ b/lib/intcode/intcode.zig @@ -80,6 +80,19 @@ pub const Machine = struct { program[@intCast(usize, dest)] = result; self.ip += 4; }, + 3 => { + const input = self.input.orderedRemove(0); + const dest = program[self.ip + 1]; + + program[@intCast(usize, dest)] = input; + self.ip += 2; + }, + 4 => { + const output = program[@intCast(usize, program[self.ip + 1])]; + + try self.output.append(output); + self.ip += 2; + }, 99 => { self.ip += 1; return false; @@ -139,7 +152,7 @@ test "day 2 example 5" { test "day 5 example 1" { var before: [5]i32 = .{ 3, 0, 4, 0, 99 }; - var after = before; + var after: [5]i32 = .{ 666, 0, 4, 0, 99 }; var machine = try Machine.init(test_allocator, before[0..before.len]); try machine.input.append(666);