~cricket/advent2020

8263b1ea2e6ef65e18b024decd38b19e87de3cd4 — cricket 9 months ago 1a42d34
day 5: c o n c i s e
1 files changed, 5 insertions(+), 14 deletions(-)

M 5/main.zig
M 5/main.zig => 5/main.zig +5 -14
@@ 1,11 1,11 @@
const std = @import("std");
const input = @embedFile("input");
const mem = std.mem;
const fmt = std.fmt;

const print = std.debug.print;

fn run(a: *mem.Allocator) [2]usize {
pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const a = &gpa.allocator;
    var strings = mem.split(input, "\n");
    var ids = std.AutoHashMap(usize, bool).init(a);
    var max: usize = 0;


@@ 19,15 19,6 @@ fn run(a: *mem.Allocator) [2]usize {
        if (id > max) max = id;
    }
    var i = max;
    while (i > 0) : ( i -= 1 ) {
        _ = ids.get(i) orelse return .{max, i};
    }
    return .{0, 0};
    while (i > 0) : (i -= 1) _ = ids.get(i) orelse break;
    print("part 1: {}\npart 2: {}\n", .{max, i});
}

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const a = &gpa.allocator;
    var p = run(a);
    print("part 1: {}\npart 2: {}\n", .{p[0], p[1]});
}
\ No newline at end of file