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

10
input/day1/p1-test.txt Normal file
View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

View File

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