Day 3 Question 1, Plus some day2 stuff?

This commit is contained in:
2025-12-03 12:55:59 +02:00
parent da62aa3d80
commit cb25bbe5a4
4 changed files with 245 additions and 2 deletions

41
Day3/Question1/main.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
int main() {
std::fstream input("input");
std::string currentLine = "";
uint64_t totalJolt = 0, lineLength = 0;
while (std::getline(input, currentLine)) {
char mostSignificantDigit = '0', leastSignificantDigit = '0';
lineLength = currentLine.length();
for (uint16_t currentPosition = 0; currentPosition < lineLength;
currentPosition++) {
char digit = currentLine[currentPosition];
if (mostSignificantDigit < digit) {
// Since this is the last digit
if (currentPosition == lineLength - 1) {
leastSignificantDigit = digit;
continue;
}
// Otherwise business as usual
mostSignificantDigit = digit;
leastSignificantDigit = '0';
continue;
}
if (leastSignificantDigit < digit) {
leastSignificantDigit = digit;
}
}
// Just a simple char > uint conversion
totalJolt +=
(10 * (mostSignificantDigit - 48)) + (leastSignificantDigit - 48);
}
std::cout << totalJolt << "\n";
return 0;
}