D1P1 Done

This commit is contained in:
2025-12-01 02:02:04 -05:00
parent 01b072a641
commit 349b87bf57
2 changed files with 20 additions and 10 deletions

View File

@@ -125,13 +125,8 @@ auto parse(const std::string& filename) -> std::expected<std::vector<instruction
return instructions;
}
int rotate (int state, const bool direction, int number) {
if (direction) {
// Right (positive)
} else {
// Left (negative)
}
int rotate (const int state, const bool direction, const int number) {
if (direction) { return (state + 100 + number) % 100; } else { return (state + 100 - number) % 100; }
}
int main() {
@@ -143,10 +138,15 @@ int main() {
}
int state = 50;
for (instruction i : instructions) {
rotate(state, i.dir, i.number);
int password = 0;
for (auto [dir, number] : instructions) {
state = rotate(state, dir, number);
if (state == 0) {
password++;
}
}
std::cout << "Password: " << password << std::endl;
return 0;
}