Switch to i64 for words

This commit is contained in:
2019-12-09 10:48:40 +00:00
parent 96e35f265e
commit 289aa920d0
4 changed files with 55 additions and 54 deletions

View File

@@ -1,7 +1,7 @@
const std = @import("std");
const intcode = @import("intcode");
fn run(alloc: *std.mem.Allocator, program: []i32, noun: i32, verb: i32) !i32 {
fn run(alloc: *std.mem.Allocator, program: []intcode.Word, noun: intcode.Word, verb: intcode.Word) !intcode.Word {
program[1] = noun;
program[2] = verb;
@@ -10,11 +10,11 @@ fn run(alloc: *std.mem.Allocator, program: []i32, noun: i32, verb: i32) !i32 {
return program[0];
}
fn runCopy(alloc: *std.mem.Allocator, program: []i32, noun: i32, verb: i32) !i32 {
var memory = try alloc.alloc(i32, program.len);
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(i32, memory, program);
std.mem.copy(intcode.Word, memory, program);
return run(alloc, memory, noun, verb);
}
@@ -31,14 +31,14 @@ pub fn main() anyerror!void {
std.debug.warn("Day 2, Part 1: {}\n", try runCopy(alloc, program, 12, 2));
// Part 2: 100*100 = 10,000 combinations to try.
var memory: []i32 = try alloc.alloc(i32, program.len);
var memory: []intcode.Word = try alloc.alloc(intcode.Word, program.len);
var done: bool = false;
var noun: i32 = 0;
var verb: i32 = 0;
var noun: intcode.Word = 0;
var verb: intcode.Word = 0;
std.debug.warn("Day 2, Part 2: ");
while (!done) {
std.mem.copy(i32, memory, program);
std.mem.copy(intcode.Word, memory, program);
const result = try run(alloc, memory, noun, verb);
// Too high: 250800 (noun=33, verb=76)