aoc2022/day2/puzzle2.zig

31 lines
745 B
Zig

const std = @import("std");
const mem = std.mem;
const fmt = std.fmt;
const print = std.debug.print;
const input = @embedFile("input");
pub fn main() !void {
var total_points: u32 = 0;
// Split the input
var input_iter = mem.split(u8, input, "\n");
while (input_iter.next()) |line| {
// Input ends with an empty line
if (line.len == 0) continue;
// Converting character code to points
const op = line[0] -| 'A';
const me = line[2] -| 'X';
// A 3 1 2
// B 1 2 3
// C 2 3 1
// X Y Z
// This works, OK? Trust me bro
total_points += ((me + op + 2) % 3) + 1 + (me * 3);
}
print("{}\n", .{total_points});
}