This commit is contained in:
2019-12-06 00:44:48 +00:00
parent ec0fc3ef1b
commit 881cdd6e32
2 changed files with 64 additions and 8 deletions

View File

@@ -7,14 +7,26 @@ pub fn main() anyerror!void {
const alloc = &arena.allocator;
var program = try intcode.loadFromStdIn(alloc);
var machine = try intcode.Machine.init(alloc, program);
var p1 = try intcode.loadFromStdIn(alloc);
var p2 = try alloc.alloc(i32, p1.len);
std.mem.copy(i32, p2, p1);
try machine.input.append(1); // Air conditioner unit
try machine.run();
var m1 = try intcode.Machine.init(alloc, p1);
var m2 = try intcode.Machine.init(alloc, p2);
std.debug.warn("Part 1\n");
for (machine.output.toSlice()) |value, idx| {
try m1.input.append(1); // Air conditioner unit
try m1.run();
for (m1.output.toSlice()) |value, idx| {
std.debug.warn("Test {}: {}\n", idx, value);
}
std.debug.warn("\nPart 2\n");
try m2.input.append(5); // Thermal radiator controller
try m2.run();
for (m2.output.toSlice()) |value, idx| {
std.debug.warn("Test {}: {}\n", idx, value);
}
}