D1P1 Done
This commit is contained in:
10
input/day1/p1-test.txt
Normal file
10
input/day1/p1-test.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
@@ -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