Day 2
This commit is contained in:
parent
83f75486a1
commit
1e64c4c56f
|
@ -25,11 +25,11 @@ pub fn main() !void {
|
||||||
//scissors - rock = 2 WIN
|
//scissors - rock = 2 WIN
|
||||||
//scissors - paper = 1 LOSE
|
//scissors - paper = 1 LOSE
|
||||||
|
|
||||||
switch (op - me) {
|
total_points += switch (op - me) {
|
||||||
-1, 2 => total_points += 6,
|
-1, 2 => 6,
|
||||||
-2, 1 => total_points += 0,
|
-2, 1 => 0,
|
||||||
else => total_points += 3,
|
else => 3,
|
||||||
}
|
};
|
||||||
|
|
||||||
total_points += @intCast(u4, me);
|
total_points += @intCast(u4, me);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
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});
|
||||||
|
}
|
Loading…
Reference in New Issue