Further simplify code

This commit is contained in:
Jose Caban
2025-12-01 16:53:53 -05:00
parent 56d5f3fc54
commit dd0c70341e

View File

@@ -82,15 +82,16 @@ public:
char direction = line[0]; char direction = line[0];
int amount = std::stoi(line.substr(1)); int amount = std::stoi(line.substr(1));
if (direction == 'L') { switch (direction) {
dial.TurnLeft(amount); case 'L':
dial.TurnLeft(amount);
break;
case 'R':
dial.TurnRight(amount);
break;
default:
assert(false && "Invalid direction");
} }
else if (direction == 'R') {
dial.TurnRight(amount);
}
else {
assert(false && "Invalid direction");
}
if (dial.GetPosition() == 0) { if (dial.GetPosition() == 0) {
password++; password++;
@@ -108,14 +109,15 @@ public:
char direction = line[0]; char direction = line[0];
int amount = std::stoi(line.substr(1)); int amount = std::stoi(line.substr(1));
if (direction == 'L') { switch (direction) {
clicksAtZero += dial.TurnLeft(amount); case 'L':
} clicksAtZero += dial.TurnLeft(amount);
else if (direction == 'R') { break;
clicksAtZero += dial.TurnRight(amount); case 'R':
} clicksAtZero += dial.TurnRight(amount);
else { break;
assert(false && "Invalid direction"); default:
assert(false && "Invalid direction");
} }
} }
return std::to_string(clicksAtZero); return std::to_string(clicksAtZero);