39 lines
1.0 KiB
C
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;
|
|
}
|
|
|