master
Raw Download raw file
 1const std = @import("std");
 2const io = std.io;
 3const fmt = std.fmt;
 4
 5pub fn main() !void {
 6    const stdin = io.getStdIn().reader();
 7    const allocator = std.heap.page_allocator;
 8    var depthHistory = std.ArrayList(u16).init(allocator);
 9    defer depthHistory.deinit();
10
11    var buf: [1024]u8 = undefined;
12    while (try stdin.readUntilDelimiterOrEof(&buf, '\n')) |line| {
13        const depth = fmt.parseUnsigned(u16, line, 10) catch {
14            std.debug.print("PARSE ERR: {s}\n", .{line});
15            continue;
16        };
17        try depthHistory.append(depth);
18    }
19    var inc: u16 = 0;
20    for (depthHistory.items) |d,i| {
21        if (i > 0) {
22            const prev = depthHistory.items[i-1];
23            if (prev < d){
24                inc += 1;
25            }
26        }
27    }
28    std.debug.print("{d}\n", .{inc});
29}