blob: 5ff7dc04ca1b16d8fbaba9197c72cebb9248325b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
const std = @import("std");
const example = @embedFile("example");
const example2 = @embedFile("example2");
const example3 = @embedFile("example3");
const example4 = @embedFile("example4");
const example5 = @embedFile("example5");
const input = @embedFile("input");
pub fn main() anyerror!void {
try std.testing.expectEqual(solve(example), 19);
try std.testing.expectEqual(solve(example2), 23);
try std.testing.expectEqual(solve(example3), 23);
try std.testing.expectEqual(solve(example4), 29);
try std.testing.expectEqual(solve(example5), 26);
const result = solve(input);
try std.io.getStdOut().writer().print("{}\n", .{result});
}
fn solve(puzzle: []const u8) u64 {
var n: u64 = 13;
outer: while (true) : (n += 1) {
var i: u64 = n;
while (i >= n - 13) : (i -= 1) {
var j: u64 = i - 1;
while (j >= n - 13) : (j -= 1) {
if (puzzle[i] == puzzle[j]) {
continue :outer;
}
if (j == 0) {
break;
}
}
}
return n + 1;
}
}
|