2022-06 in zig
This commit is contained in:
parent
f93b2ed7a9
commit
68f3c84d68
8 changed files with 71 additions and 0 deletions
28
2022/06-tuning-trouble/first.zig
Normal file
28
2022/06-tuning-trouble/first.zig
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue