#import "Basic";
#import "String";
#import "File";
numbers :: string.[
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
];
solve_day1 :: (test: bool) {
contents := read_entire_file("inputs/day1.txt");
lines := split(contents, "\n");
ss := to_s128(-1);
part1 := 0;
part2 := 0;
for line: lines {
if line.count == 0 continue;
first_digit_part1 := -1;
second_digit_part1 := -1;
first_digit_part2 := -1;
second_digit_part2 := -1;
for 0..line.count - 1 {
digit_found := -1;
is_single_digit := false;
if line[it] >= #char "0" && line[it] <= #char "9" {
digit_found = line[it] - #char "0";
is_single_digit = true;
} else {
for number, number_index: numbers {
if begins_with(slice(line, it, line.count), number) {
digit_found = cast(u8)(number_index);
}
}
}
if digit_found != -1 {
if is_single_digit {
if first_digit_part1 == -1 {
first_digit_part1 = digit_found;
}
second_digit_part1 = digit_found;
}
if first_digit_part2 == -1 {
first_digit_part2 = digit_found;
}
second_digit_part2 = digit_found;
}
}
part1 += first_digit_part1 * 10 + second_digit_part1;
part2 += first_digit_part2 * 10 + second_digit_part2;
}
print("Part 1: %\n", part1);
print("Part 2: %\n", part2);
}