Add character devices
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
const std = @import("std");
|
||||
const intcode = @import("intcode");
|
||||
|
||||
fn run(program: []i32, noun: i32, verb: i32) i32 {
|
||||
fn run(alloc: *std.mem.Allocator, program: []i32, noun: i32, verb: i32) !i32 {
|
||||
program[1] = noun;
|
||||
program[2] = verb;
|
||||
|
||||
var machine = &intcode.Machine{ .memory = program, .ip = 0 };
|
||||
|
||||
machine.run();
|
||||
var machine = try intcode.Machine.Run(alloc, program);
|
||||
|
||||
return program[0];
|
||||
}
|
||||
|
||||
fn runCopy(alloc: *std.mem.Allocator, program: []i32, noun: i32, verb: i32) anyerror!i32 {
|
||||
fn runCopy(alloc: *std.mem.Allocator, program: []i32, noun: i32, verb: i32) !i32 {
|
||||
var memory = try alloc.alloc(i32, program.len);
|
||||
defer alloc.free(memory);
|
||||
|
||||
std.mem.copy(i32, memory, program);
|
||||
|
||||
return run(memory, noun, verb);
|
||||
return run(alloc, memory, noun, verb);
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
@@ -41,7 +39,7 @@ pub fn main() anyerror!void {
|
||||
std.debug.warn("Part 2: Searching...");
|
||||
while (!done) {
|
||||
std.mem.copy(i32, memory, program);
|
||||
const result = run(memory, noun, verb);
|
||||
const result = try run(alloc, memory, noun, verb);
|
||||
|
||||
// Too high: 250800 (noun=33, verb=76)
|
||||
if (result == 19690720) {
|
||||
|
Reference in New Issue
Block a user