solve_day4 :: (test: bool) {
content := read_entire_file(ifx test then "inputs/day4_test.txt" else "inputs/day4.txt");
lines := split(content, "\n");
part1 := 0;
part2 := 0;
for line: lines {
index_of_command := find_index_from_left(line, ",");
reset_temporary_storage();
ranges := split(line, ",",, temp);
pair: Range_Pair = ---;
numbers := split(ranges[0], "-",, temp);
pair.first.start = string_to_int(numbers[0], 10, u64);
pair.first.end = string_to_int(numbers[1], 10, u64);
numbers = split(ranges[1], "-",, temp);
pair.second.start = string_to_int(numbers[0], 10, u64);
pair.second.end = string_to_int(numbers[1], 10, u64);
if (pair.first.start >= pair.second.start && pair.first.end <= pair.second.end) ||
(pair.first.start <= pair.second.start && pair.first.end >= pair.second.end) {
part1 += 1;
}
if (pair.first.start >= pair.second.start && pair.first.start <= pair.second.end) ||
(pair.first.end >= pair.second.start && pair.first.end <= pair.second.end) ||
(pair.first.start <= pair.second.start && pair.first.end >= pair.second.start) ||
(pair.first.start <= pair.second.end && pair.first.end >= pair.second.end) {
part2 += 1;
}
}
print("Part 1: %\n", part1);
print("Part 2: %\n", part2);
}
#scope_file
Range_Pair :: struct {
first: Elf_Range;
second: Elf_Range;
}
Elf_Range :: struct {
start: u64;
end: u64;
}