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;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user