Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const std = @import("std");
- const warn = std.debug.warn;
- fn solve() [2]u64 {
- const f = @embedFile("Input.txt");
- comptime var part1: u64 = 0;
- comptime var part2: u64 = 0;
- comptime var start = 0;
- comptime var next = 1;
- comptime var half = f.len >> 1;
- while (half != f.len): ({start += 1; next += 1; half += 1;}) {
- part1 += (f[start] - 48) & - (@boolToInt(f[start] == f[next]));
- part2 += (f[start] - 48) & - (@boolToInt(f[start] == f[half]));
- //if (f[start] == f[next]) {
- // part1 += f[start] - 48;
- //}
- //if (f[start] == f[half]) {
- // part2 += f[start] - 48;
- //}
- }
- while (next != f.len): ({start += 1; next += 1;}) {
- if (f[start] == f[next]) {
- part1 += f[start] - 48;
- }
- }
- if (f[0] == f[f.len - 1]) {
- part1 += f[0] - 48;
- }
- return [2]u64 {part1, part2 * 2};
- }
- pub fn main() void {
- comptime @setEvalBranchQuota(2500);
- const foo = comptime solve();
- warn("{} {}\n", foo[0], foo[1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment