const std = @import("std");
const ArrayList = std.ArrayList;
const StringHashMap = std.StringHashMap;

const PathPair = struct {
    left: [3]u8 = undefined,
    right: [3]u8 = undefined,
};

pub fn solve_part1(allocator: std.mem.Allocator, file_name: []const u8) !void {
    var inputs = try std.fs.cwd().openFile(file_name, .{});
    var buffered_reader = std.io.bufferedReader(inputs.reader());
    var in_stream = buffered_reader.reader();

    var path_map = StringHashMap(PathPair).init(allocator);

    var instructions = try in_stream.readUntilDelimiterAlloc(allocator, '\n', 100 * 1024);
    _ = instructions;

    try in_stream.skipUntilDelimiterOrEof('\n');

    var buffer: [1024]u8 = undefined;

    while (try in_stream.readUntilDelimiterOrEof(&buffer, '\n')) |line| {
        var path = line[0..3];

        var pair: PathPair = .{};

        @memcpy(&pair.left, line[7..10]);
        @memcpy(&pair.right, line[11..14]);

        try path_map.put(path, pair);
    }

    var iter = path_map.iterator();

    while (iter.next()) |kv| {
        std.log.info("{s} = ({s}, {s})", .{ kv.key_ptr.*, kv.value_ptr.left, kv.value_ptr.right });
    }
}