Idiot version for dayp2
This commit is contained in:
parent
38eca3b747
commit
86dcbd3aaf
1 changed files with 52 additions and 11 deletions
|
|
@ -31,43 +31,84 @@ constexpr int maxDial = 100 ;
|
||||||
|
|
||||||
auto executeSafeCrack(const std::vector<DialRotation>& dialRotations){
|
auto executeSafeCrack(const std::vector<DialRotation>& dialRotations){
|
||||||
int dial {dialStart};
|
int dial {dialStart};
|
||||||
int countZero {};
|
std::cout << "The dial starts by pointing at " << dial << "\n";
|
||||||
|
int countZero = 0;
|
||||||
|
|
||||||
for (const auto& curDial : dialRotations){
|
for (const auto& curDial : dialRotations){
|
||||||
|
int fullRotations = curDial.distance / maxDial;
|
||||||
|
int modulo = curDial.distance % maxDial;
|
||||||
|
|
||||||
|
if (fullRotations > 0){
|
||||||
|
std::cout << "Big number! Passed " << "" << fullRotations << " times through 0!\n";
|
||||||
|
countZero += fullRotations;
|
||||||
|
}
|
||||||
|
|
||||||
if(curDial.direction == 'L'){
|
if(curDial.direction == 'L'){
|
||||||
dial -= curDial.distance % maxDial;
|
int prevDial = dial;
|
||||||
|
dial -= modulo;
|
||||||
if (dial < 0){
|
if (dial < 0){
|
||||||
dial += maxDial;
|
dial += maxDial;
|
||||||
|
if (prevDial != 0) {
|
||||||
|
std::cout << "Passed through 0 from a L rotation! Count++!\n";
|
||||||
|
countZero++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dial == 0){
|
||||||
|
std::cout << "Stopped at 0! Count++!\n";
|
||||||
|
countZero++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
dial += curDial.distance % maxDial;
|
dial += modulo;
|
||||||
if (dial > maxDial - 1){
|
if (dial >= maxDial){
|
||||||
dial -= maxDial;
|
dial -= maxDial;
|
||||||
|
countZero++;
|
||||||
|
std::cout << "Passed through 0 from a R rotation! Count++!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::println("{} : {:3}, Dial now at: {:5}", curDial.direction, curDial.distance, dial);
|
|
||||||
if (dial == 0){
|
|
||||||
countZero++;
|
|
||||||
}
|
std::println("{} : {:3}, Dial now at: {:5} cnt: {}", curDial.direction, curDial.distance, dial, countZero);
|
||||||
if (dial < 0){
|
if (dial < 0){
|
||||||
|
std::cout << "Shit's fucked!\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (dial > maxDial){
|
if (dial >= maxDial){
|
||||||
|
std::cout << "Shit's fucked!\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::print("Zeros: {}", countZero);
|
std::print("Zeros: {}\n", countZero);
|
||||||
|
return countZero;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto main(int, char**) -> int {
|
auto main(int, char**) -> int {
|
||||||
std::cout << "Hello, from aoc25 day1!!\n";
|
std::cout << "Hello, from aoc25 day1!!\n";
|
||||||
auto retval = parseRotations("day1_input");
|
auto retval = parseRotations("day1_input");
|
||||||
|
|
||||||
|
std::vector<DialRotation> testCase = {
|
||||||
|
{'L', 68},
|
||||||
|
{'L', 30},
|
||||||
|
{'R', 48},
|
||||||
|
{'L', 5},
|
||||||
|
{'R', 60},
|
||||||
|
{'L', 55},
|
||||||
|
{'L', 1},
|
||||||
|
{'L', 99},
|
||||||
|
{'R', 14},
|
||||||
|
{'L', 82},
|
||||||
|
{'L', 1000},
|
||||||
|
};
|
||||||
|
|
||||||
if(retval)
|
if(retval)
|
||||||
{
|
{
|
||||||
executeSafeCrack(*retval);
|
auto realResult = executeSafeCrack(*retval);
|
||||||
|
auto result = executeSafeCrack(testCase);
|
||||||
|
std::println("Testcase result: {}", result);
|
||||||
|
std::println("Total result: {}", realResult);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
std::print("{}\n", retval.error());
|
std::print("{}\n", retval.error());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue