Files
advent-of-code-2025/day3.c
Daniel Ledda a67e150d0f update
2025-12-25 14:05:36 +01:00

39 lines
1.0 KiB
C

#define DJSTD_BASIC_ENTRY
#include "./djstdlib/core.c"
int djstd_entry(Arena *arena, StringList args) {
string input = os_readEntireFile(arena, s("./day3-input"));
StringList split = strSplit(arena, s("\n"), input);
int32 maxJoltage = 0;
for (EachEl(split, string, line)) {
if (strEql(*line, s(""))) {
break;
}
int32 firstDigit = 0;
int32 secondDigit = 0;
int32 secondDigStart = 0;
for (int32 i = 0; i < line->length - 1; i++) {
int32 currDigit = line->str[i] - '0';
if (firstDigit < currDigit) {
firstDigit = currDigit;
secondDigStart = i + 1;
}
}
for (int i = secondDigStart; i < line->length; i++) {
int32 currDigit = line->str[i] - '0';
if (secondDigit < currDigit) {
secondDigit = currDigit;
}
}
maxJoltage += firstDigit * 10 + secondDigit;
}
println("%d", maxJoltage);
return 0;
}