Day 1 solved
This commit is contained in:
4126
Day1/Question1/input
Normal file
4126
Day1/Question1/input
Normal file
File diff suppressed because it is too large
Load Diff
18
Day1/Question1/main.cpp
Normal file
18
Day1/Question1/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
std::fstream inputFile("input");
|
||||
std::string currentLine;
|
||||
int16_t counter = 50, number = 0, password = 0;
|
||||
|
||||
while (std::getline(inputFile, currentLine)) {
|
||||
number = std::stoi(currentLine.substr(1));
|
||||
counter = (counter + ((currentLine[0] == 'L') * 2 - 1) * number) % 100;
|
||||
password += counter == 0 ? 1 : 0;
|
||||
}
|
||||
std::cout << password << std::endl;
|
||||
return 0;
|
||||
}
|
||||
4126
Day1/Question2/input
Normal file
4126
Day1/Question2/input
Normal file
File diff suppressed because it is too large
Load Diff
11
Day1/Question2/inputTest
Normal file
11
Day1/Question2/inputTest
Normal file
@@ -0,0 +1,11 @@
|
||||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
L133
|
||||
37
Day1/Question2/main.cpp
Normal file
37
Day1/Question2/main.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
std::fstream inputFile("input");
|
||||
std::string currentLine;
|
||||
int16_t counter = 50, number = 0, password = 0, remainder = 0, hold = 0;
|
||||
bool isRotatingDown; // This is pretty arbitrary, could've bee isRotatingUp
|
||||
|
||||
while (std::getline(inputFile, currentLine)) {
|
||||
// Get the number
|
||||
isRotatingDown = currentLine[0] == 'L';
|
||||
number = std::stoi(currentLine.substr(1));
|
||||
remainder = number % 100;
|
||||
|
||||
// Redundant rotations
|
||||
// Neat thing is if it is less than 100, this gives a 0
|
||||
password += (number - remainder) / 100;
|
||||
|
||||
// Remainder is the non reduntant turns we will do
|
||||
hold = counter + (remainder * (isRotatingDown ? -1 : 1));
|
||||
|
||||
// its bit of a hack since in C++ true is same as 1 and false is same as 0
|
||||
// This also works since maximum counter can be is 99 and maximum remainder
|
||||
// is 99 so it is 198 (so max 1 rotation)
|
||||
// and lowest possible is -99 (again only 1)
|
||||
password += isRotatingDown && counter != 0 ? (hold <= 0) : (hold >= 100);
|
||||
|
||||
// Rotating back
|
||||
counter = hold % 100;
|
||||
counter += counter < 0 ? 100 : 0;
|
||||
}
|
||||
std::cout << password << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user