#include #include #include #include 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; }