Add '2019/' from commit 'fc21396bc86bc0f706225f4f6e1d8294d344ca53'

git-subtree-dir: 2019
git-subtree-mainline: f1be11fca8
git-subtree-split: fc21396bc8
This commit is contained in:
2022-01-09 17:07:24 +00:00
36 changed files with 2978 additions and 0 deletions

29
2019/05/src/main.zig Normal file
View File

@@ -0,0 +1,29 @@
const std = @import("std");
const intcode = @import("intcode");
pub fn main() anyerror!void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const alloc = &arena.allocator;
var p1 = try intcode.loadFromStdIn(alloc);
var p2 = try alloc.alloc(intcode.Word, p1.len);
std.mem.copy(intcode.Word, p2, p1);
var m1 = try intcode.Machine.init(alloc, p1);
var m2 = try intcode.Machine.init(alloc, p2);
try m1.writeToInput(1); // Air conditioner unit
try m1.run();
var out: intcode.Word = 0;
while (out == 0) : (out = try m1.readFromOutput()) {}
std.debug.warn("Day 5, Part 1: {}\n", out);
try m2.writeToInput(5); // Thermal radiator controller
try m2.run();
std.debug.warn("Day 5, Part 2: {}\n", try m2.readFromOutput());
}