This commit is contained in:
2019-12-02 21:37:21 +00:00
parent 637f909678
commit 14eff1a60c
2 changed files with 34 additions and 4 deletions

View File

@@ -11,4 +11,34 @@ pub fn main() anyerror!void {
// Part 1
std.debug.warn("Part 1: {}\n", try intcode.runCopy(alloc, program, 12, 2));
// Part 2: 100*100 = 10,000 combinations to try.
var memory: []u32 = try alloc.alloc(u32, program.len);
var done: bool = false;
var noun: u32 = 0;
var verb: u32 = 0;
std.debug.warn("Part 2: Searching...");
while (!done) {
std.mem.copy(u32, memory, program);
const result = try intcode.run(memory, noun, verb);
// Too high: 250800 (noun=33, verb=76)
if (result == 19690720) {
std.debug.warn("OK! noun={} verb={}\n", noun, verb);
done = true;
}
noun += 1;
if (noun > 100) {
noun = 0;
verb += 1;
if (verb > 100) {
std.debug.warn("failed!\n");
} else {
std.debug.warn(".");
}
}
}
}