Guest User

Untitled

a guest
Aug 15th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. const std = @import("std");
  2. const warn = std.debug.warn;
  3.  
  4. fn solve() [2]u64 {
  5.     const f = @embedFile("Input.txt");
  6.  
  7.     comptime var part1: u64 = 0;
  8.     comptime var part2: u64 = 0;
  9.  
  10.     comptime var start = 0;
  11.     comptime var next = 1;
  12.     comptime var half = f.len >> 1;
  13.  
  14.     while (half != f.len): ({start += 1; next += 1; half += 1;}) {
  15.         part1 += (f[start] - 48) & - (@boolToInt(f[start] == f[next]));
  16.         part2 += (f[start] - 48) & - (@boolToInt(f[start] == f[half]));
  17.        
  18.         //if (f[start] == f[next]) {
  19.         //    part1 += f[start] - 48;
  20.         //}
  21.  
  22.         //if (f[start] == f[half]) {
  23.         //    part2 += f[start] - 48;
  24.         //}
  25.     }
  26.    
  27.     while (next != f.len): ({start += 1; next += 1;}) {
  28.         if (f[start] == f[next]) {
  29.             part1 += f[start] - 48;
  30.         }
  31.     }
  32.  
  33.     if (f[0] == f[f.len - 1]) {
  34.         part1 += f[0] - 48;
  35.     }
  36.     return [2]u64 {part1, part2 * 2};
  37. }
  38.  
  39. pub fn main() void {
  40.     comptime @setEvalBranchQuota(2500);
  41.     const foo = comptime solve();
  42.  
  43.     warn("{} {}\n", foo[0], foo[1]);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment