~cricket/advent2020

f2c51032683ba8bbe23988f3b5c31f026d91a59f — cricket 9 months ago 84f7d5e
stupid compact

* why? idk lol
1 files changed, 6 insertions(+), 12 deletions(-)

M 3/main.zig
M 3/main.zig => 3/main.zig +6 -12
@@ 1,15 1,9 @@
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 });
}
\ No newline at end of file
fn slope(sx: usize, sy: usize) usize {var t:usize=0;var x=t;var y=t;var i=t;
    while (i<input.len):({y+=sy;x+=sx;i=(w*y)+(x%(w-1));}) t+=@boolToInt(input[i]=='#');
    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",.{p2,p2});}
\ No newline at end of file