Implement opcodes 3 and 4, naively
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user