finish day3 part 1

This commit is contained in:
2026-06-22 10:34:47 -04:00
parent b8ba9942f5
commit db36cc6fa9
2 changed files with 244 additions and 0 deletions

44
day3.jai Normal file
View File

@@ -0,0 +1,44 @@
sample :: #string END
987654321111111
811111111111119
234234234234278
818181911112111
END;
main :: () {
content := read_entire_file("day3.input");
solve_first(content);
}
solve_first :: (input: string) {
total := 0;
for line: split(input, "\n") {
if line.count == 0 continue;
assert(line.count > 1);
biggest_first_digit := 0;
biggest_first_digit_index := 0;
for i: 0..line.count - 2 {
char := line[i] - #char "0";
if char > biggest_first_digit {
biggest_first_digit = char;
biggest_first_digit_index = i;
}
}
biggest_second_digit := 0;
print("-----\n");
for i: biggest_first_digit_index + 1..line.count - 1 {
char := line[i] - #char "0";
print("%: %\n", i, char);
if char > biggest_second_digit {
biggest_second_digit = char;
}
}
total += biggest_first_digit * 10 + biggest_second_digit;
print("%: %\n", it_index, biggest_first_digit * 10 + biggest_second_digit);
}
print("%\n", total);
}
#import "Basic";
#import "File";
#import "String";