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<^<<>vv>>vv<vvv>><><v<>><^<v>^><^<<v>><v><v>^<v>><>v^^^^v<v^^v<>^^vv<>v<>v>^vv^><v^<<^<>^<>^^^>v^>>>v><<^>>v<^v<>^^<v<><v^v<v>v<><v<vv><<>v<^<^>v<>v^>v>^^<<<^^vv^<><<<>>v>^^<>v>>>><v<v<^^^v<v<v^><<>v^v<>v>><<<<v^<><^<<^>^<vvv<v^^v>>v^vv^><^v^^<>^^><<v^>>vv>^<v^vv<^^v<>>vvv<^v^>>^<v<v>>^>^^<<^>^>^v><>>^<^^v>^>>^^<><>>>^^>^^vvv>v<^^<>v^v^^<v<<^<v^v^<<>v^v<v<<v<>>><<^^^>>v>^vv>^>^^v<>^^<>v^^<><v<v<vvv^<vv<<>v^><<><v<>vv<<^vvvv><<<v>v>v^>v^<>v^>^<v<vvv^>^<>^>^^v<>><<<><v<^^>^v<v>^^v^v<<<^v^<>^<>v>^^>v<v<v>v>^^<<<><<^>v<v<^vv^v><^^<<vv>^<<v><>^>>>>><v^v<<<^>^v^v<<v<>vvv<<>v>v>>^v^v^>><<<<>v^<v<><<>>>^>>^>><<v>
const std = @import("std");
const Str = []const u8;
const PATH = "input/day03.txt";
pub fn first(allocator: std.mem.Allocator) !usize {
return try coordCounter(allocator, @embedFile(PATH));
}
pub fn second(allocator: std.mem.Allocator) !usize {
return try roboCoordCounter(allocator, @embedFile(PATH));
}
const Coord = [2]i8;
fn coordCounter(allocator: std.mem.Allocator, in: Str) !usize {
var crd: Coord = .{ 0, 0 };
var seen = std.AutoHashMap(Coord, void).init(allocator);
defer seen.deinit();
try seen.put(crd, {});
for (in) |ch| {
switch (ch) {
'^' => crd[1] += 1,
'v' => crd[1] -= 1,
'>' => crd[0] += 1,
'<' => crd[0] -= 1,
else => {},
}
try seen.put(crd, {});
}
return seen.count();
}
fn roboCoordCounter(allocator: std.mem.Allocator, in: Str) !usize {
var santa: Coord = .{ 0, 0 };
var robo_santa: Coord = .{ 0, 0 };
var seen = std.AutoHashMap(Coord, void).init(allocator);
defer seen.deinit();
try seen.put(santa, {});
for (in) |ch, idx| {
if (idx % 2 == 0) {
switch (ch) {
'^' => santa[1] += 1,
'v' => santa[1] -= 1,
'>' => santa[0] += 1,
'<' => santa[0] -= 1,
else => {},
}
try seen.put(santa, {});
} else {
switch (ch) {
'^' => robo_santa[1] += 1,
'v' => robo_santa[1] -= 1,
'>' => robo_santa[0] += 1,
'<' => robo_santa[0] -= 1,
else => {},
}
try seen.put(robo_santa, {});
}
}
return seen.count();
}
test "Santa" {
try std.testing.expectEqual(@as(usize, 2), try coordCounter(std.testing.allocator, ">"));
try std.testing.expectEqual(@as(usize, 4), try coordCounter(std.testing.allocator, "^>v<"));
try std.testing.expectEqual(@as(usize, 2), try coordCounter(std.testing.allocator, "^v^v^v^v^v"));
}
test "Robo-Santa" {
try std.testing.expectEqual(@as(usize, 3), try roboCoordCounter(std.testing.allocator, "^v"));
try std.testing.expectEqual(@as(usize, 3), try roboCoordCounter(std.testing.allocator, "^>v<"));
try std.testing.expectEqual(@as(usize, 11), try roboCoordCounter(std.testing.allocator, "^v^v^v^v^v"));
}
test "day03a" {
try std.testing.expectEqual(@as(usize, 2565), try first(std.testing.allocator));
}
test "day03b" {
try std.testing.expectEqual(@as(usize, 2639), try second(std.testing.allocator));
}