51 lines
1.3 KiB
Zig
51 lines
1.3 KiB
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 {
|
||
|
|
||
|
const checked_len : usize = 'z' + 1;
|
||
|
var checked = [_]bool{false} ** checked_len;
|
||
|
|
||
|
var total_points : usize = 0;
|
||
|
|
||
|
// Split the input
|
||
|
var input_iter = mem.split(u8, input, "\n");
|
||
|
while (input_iter.next()) |line| {
|
||
|
if (line.len == 0) continue;
|
||
|
const length = line.len;
|
||
|
// First Half
|
||
|
for (line[0..length / 2]) |letter| {
|
||
|
checked[letter] = true;
|
||
|
}
|
||
|
// Second Half
|
||
|
for (line[length / 2..]) |letter| {
|
||
|
if (checked[letter]) {
|
||
|
if (letter >= 'a' and letter <= 'z') {
|
||
|
total_points += letter % 'a' + 1;
|
||
|
//std.debug.print("{c}:{}\n", .{letter, letter % 'a' + 1});
|
||
|
}
|
||
|
if (letter >= 'A' and letter <= 'Z') {
|
||
|
total_points += letter % 'A' + 27;
|
||
|
//std.debug.print("{c}:{}\n", .{letter, letter % 'A' + 27});
|
||
|
}
|
||
|
// Only one item is repeated
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Reset the checked letters
|
||
|
checked = [_]bool{false} ** checked_len;
|
||
|
|
||
|
}
|
||
|
|
||
|
std.debug.print("Points: {}\n", .{total_points});
|
||
|
|
||
|
}
|