#import "Basic";
#import "File";
#import "String";

solve_day2 :: (test: bool) {
    contents := read_entire_file("inputs/day2.txt");
    lines    := split(contents, "\n");

    part1 : = 0;
    part2 : = 0;
    for line, game_index: lines {
        segments := split(line, ": ");
        rolls := split(segments[1], "; ");

        red   := 0;
        green := 0;
        blue  := 0;

        for roll: rolls {

            dice := split(roll, ", ");

            for dice {
                parts := split(it, " ");

                num := string_to_int(parts[0]);
                if parts[1][0] == #char "r" {
                    red = max(red, num);
                } else if parts[1][0] == #char "g" {
                    green = max(green, num);
                } else if parts[1][0] == #char "b" {
                    blue = max(blue, num);
                }
            }
        }

        if red <= 12 && green <= 13 && blue <= 14 {
            part1 += game_index + 1;
        }

        part2 += red * green * blue;

    }

    print("Part 1: %\n", part1);
    print("Part 2: %\n", part2);
}