about summary refs log tree commit diff
path: root/day06.zig
blob: 24e20257203b8bfc814a12505b8e69852e115d60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const std = @import("std");
const data = @embedFile("day06");

fn solve(n: usize) usize {
    var i: usize = 0;
    outer: while (i < data.len - n) : (i += 1) {
        var j: usize = 0;
        while (j < n) : (j += 1) {
            var k: usize = j + 1;
            while (k < n) : (k += 1) {
                if (data[i + j] == data[i + k]) continue :outer;
            }
        }
        return i + n;
    }

    return 0;
}

pub fn main() !void {
    std.debug.print("{}\n", .{solve(4)});
    std.debug.print("{}\n", .{solve(14)});
}