~cricket/advent2020

ref: 8263b1ea2e6ef65e18b024decd38b19e87de3cd4 advent2020/5/main.zig -rw-r--r-- 723 bytes
8263b1eacricket day 5: c o n c i s e 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const std = @import("std");
const input = @embedFile("input");
const mem = std.mem;
const print = std.debug.print;

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;
    while (strings.next()) |item| {
        var id: usize = 0;
        for (item) |c| {
            id <<= 1;
            id += @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});
}