D1P1 Done
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user