This commit is contained in:
2019-12-09 11:37:00 +00:00
parent 289aa920d0
commit 421455f8ba
6 changed files with 123 additions and 24 deletions

View File

@@ -6,17 +6,13 @@ fn run(alloc: *std.mem.Allocator, program: []intcode.Word, noun: intcode.Word, v
program[2] = verb;
var machine = try intcode.Machine.Run(alloc, program);
defer machine.deinit();
return program[0];
return machine.memory[0];
}
fn runCopy(alloc: *std.mem.Allocator, program: []intcode.Word, noun: intcode.Word, verb: intcode.Word) !intcode.Word {
var memory = try alloc.alloc(intcode.Word, program.len);
defer alloc.free(memory);
std.mem.copy(intcode.Word, memory, program);
return run(alloc, memory, noun, verb);
return run(alloc, program, noun, verb);
}
pub fn main() anyerror!void {