diff options
author | Julien Dessaux | 2022-12-06 11:56:29 +0100 |
---|---|---|
committer | Julien Dessaux | 2022-12-06 11:56:29 +0100 |
commit | 68f3c84d682a7bd2d06f80db686d1cc91b58f0ce (patch) | |
tree | 4317f8924b74ac823fbf534b6f350c58fa5b7dcd /2022/06-tuning-trouble/first.zig | |
parent | 2022-05 in zig (diff) | |
download | advent-of-code-68f3c84d682a7bd2d06f80db686d1cc91b58f0ce.tar.gz advent-of-code-68f3c84d682a7bd2d06f80db686d1cc91b58f0ce.tar.bz2 advent-of-code-68f3c84d682a7bd2d06f80db686d1cc91b58f0ce.zip |
2022-06 in zig
Diffstat (limited to '2022/06-tuning-trouble/first.zig')
-rw-r--r-- | 2022/06-tuning-trouble/first.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/2022/06-tuning-trouble/first.zig b/2022/06-tuning-trouble/first.zig new file mode 100644 index 0000000..0d20f2a --- /dev/null +++ b/2022/06-tuning-trouble/first.zig @@ -0,0 +1,28 @@ +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), 7); + try std.testing.expectEqual(solve(example2), 5); + try std.testing.expectEqual(solve(example3), 6); + try std.testing.expectEqual(solve(example4), 10); + try std.testing.expectEqual(solve(example5), 11); + const result = solve(input); + try std.io.getStdOut().writer().print("{}\n", .{result}); +} + +fn solve(puzzle: []const u8) u64 { + var i: u64 = 3; + while (true) : (i += 1) { + if (puzzle[i] == puzzle[i - 1] or puzzle[i] == puzzle[i - 2] or puzzle[i] == puzzle[i - 3] or puzzle[i - 1] == puzzle[i - 2] or puzzle[i - 1] == puzzle[i - 3] or puzzle[i - 2] == puzzle[i - 3]) { + continue; + } + return i + 1; + } +} |