~cricket/advent2020

c5ac92507773c6484c536903681cee56c2c63238 — cricket 9 months ago 8263b1e
day 5: destroy readability
1 files changed, 8 insertions(+), 19 deletions(-)

M 5/main.zig
M 5/main.zig => 5/main.zig +8 -19
@@ 1,24 1,13 @@
const std = @import("std");
const input = @embedFile("input");
const mem = std.mem;
const print = std.debug.print;
const std = @import("std"); const input = @embedFile("input");

pub fn main() !void {
pub fn main() !void { var max: usize = 0;
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const a = &gpa.allocator;
    var strings = mem.split(input, "\n");
    var strings = std.mem.split(input, "\n");
    var ids = std.AutoHashMap(usize, bool).init(a);
    var max: usize = 0;
    while (strings.next()) |item| {
        var id: usize = 0;
        for (item) |c| {
            id <<= 1;
            id += @boolToInt(c == 'B' or c == 'R');
        }
    while (strings.next()) |item| { var id: usize = 0;
        for (item) |c| id = (id << 1) + @boolToInt(c == 'B' or c == 'R');
        ids.put(id, true) catch unreachable;
        if (id > max) max = id;
    }
    var i = max;
    while (i > 0) : (i -= 1) _ = ids.get(i) orelse break;
    print("part 1: {}\npart 2: {}\n", .{max, i});
}
        if (id > max) max = id; }
    var i = max; while (i > 0) : (i -= 1) _ = ids.get(i) orelse break;
    std.debug.print("part 1: {}\npart 2: {}\n", .{max, i}); }
\ No newline at end of file