~cricket/advent2020

ref: 84f7d5e11fcda7f69f437a29d0f30255965931d7 advent2020/3/main.zig -rw-r--r-- 571 bytes
84f7d5e1cricket day 3: add bigboy solution; make main solution stupid compact 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const std = @import("std");
const input = @embedFile("input");
const w = 32;

fn slope(sx: usize, sy: usize) usize {
    var t: usize = 0; var x: usize = 0; var y: usize = 0; var i: usize = 0;
    while (i < input.len) : ({ y += sy; x += sx; i = (w * y) + @mod(x, w-1); }) t += @boolToInt(input[i] == '#');
    return t;
}

pub fn main() void {
    var part1 = slope(3, 1);
    var part2: usize = 1; for ([_][2]u8{.{ 1, 1 }, .{ 3, 1 }, .{ 5, 1 }, .{ 7, 1 }, .{ 1, 2 }}) |s| part2 *= slope(s[0], s[1]);
    std.debug.print("part 1: {}\npart 2: {}\n", .{ part1, part2 });
}