You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
882 B
Zig

const input = @embedFile("inputPart2.txt");
const std = @import("std");
pub fn main() !void {
//Data wrangling
var it = std.mem.tokenize(u8, input, "\n");
var busses: [68]u32 = std.mem.zeroes([68:0]u32);
var i: u32 = 0;
while (it.next()) |line| : (i += 1) {
busses[i] = readNum(line);
}
//count total active buslines
var busTotal: u8 = 0;
for (busses) |bus| {
if (bus > 0)
busTotal += 1;
}
var stepSize: u64 = 1;
var n: u64 = 1;
for (busses, 0..) |bus, offset| {
//skip
if (bus == 0) {
continue;
}
while (((n + offset) % bus) != 0) : (n += stepSize) {}
stepSize = stepSize * bus;
}
std.debug.print("tick: {d}", .{n});
}
fn readNum(line: []const u8) u32 {
return std.fmt.parseInt(u32, line, 10) catch {
return 0;
};
}