const std = @import("std");
const lineLength = 4; // maximum line length (digits)
const decimalSize = u13; // every num in input is < 2^13
const maxItems = 2000; // number of items in input file
const path = "data/day01/input.txt";
pub fn first(allocator: ?std.mem.Allocator) anyerror!decimalSize {
_ = allocator;
const values = try parseValues();
var inc: decimalSize = 0;
for (values) |v, idx| {
if (idx == 0) continue;
if (v > values[idx - 1]) {
inc += 1;
}
}
return inc;
}
fn parseValues() anyerror![maxItems]decimalSize {
const file = @embedFile(path);
var lines = std.mem.tokenize(u8, file, "\n");
var values: [maxItems]decimalSize = undefined;
var i: decimalSize = 0;
while (lines.next()) |v| : (i += 1) {
values[i] = try std.fmt.parseUnsigned(decimalSize, v, 10);
}
return values;
}
pub fn main() anyerror!void {
var timer = try std.time.Timer.start();
const ret = try first(null);
const f = timer.lap() / 1000;
try std.testing.expectEqual(ret, @as(decimalSize, 1400));
std.debug.print("Day 1a result: {d} \t\ttime: {d}us\n", .{ ret, f });
}
test "day01a" {
try std.testing.expectEqual(@as(decimalSize, 1400), try first(std.testing.allocator));
}