Day 3 Question 1, Plus some day2 stuff?
This commit is contained in:
41
Day3/Question1/main.cpp
Normal file
41
Day3/Question1/main.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user