~cricket/advent2020

2cc8c2da962980a45736bb4f9e08b50827d8dd62 — cricket 9 months ago c5ac925
day 5: DESTROY readability
2 files changed, 10 insertions(+), 14 deletions(-)

M 3/main.zig
M 5/main.zig
M 3/main.zig => 3/main.zig +1 -1
@@ 4,4 4,4 @@ fn slope(sx:usize,sy:usize)usize{var t:usize=0;var x=t;var y=t;var i=t;
    return t;}
pub fn main()void{var p1=slope(3,1);var p2:usize=1;
    for ([_][2]u8{.{1,1},.{3,1},.{5,1},.{7,1},.{1,2}})|s|p2*=slope(s[0],s[1]);
    std.debug.print("part 1: {}\npart 2: {}\n",.{p1,p2});}
    std.debug.print("part 1: {}\npart 2: {}\n",.{p1,p2});}
\ No newline at end of file

M 5/main.zig => 5/main.zig +9 -13
@@ 1,13 1,9 @@
const std = @import("std"); const input = @embedFile("input");

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