Hey guys. so on tiresome GCD for c++.
The beginning portion of the code keeps giving me an error… I am either blind and missing a simple mistake or the level is bugged. I haven’t changed anything on it but the bottom half of the code that is suppose to be changed. The error marker shows up at the first “IF” statement. Yet, I don’t see anything wrong
// Calculate the secret number and get into the Treasury.
// Those two guys know keys for the password.
var friends = hero.findFriends();
auto number1 = friends[0].secretNumber;
auto number2 = friends[1].secretNumber;
// Just to be sure that the first number is greater.
if (number2 > number1) {
auto swap = number1;
number1 = number2;
number2 = swap;
}
// It's simple but slow function to find gcd.
auto bruteforceGCD (auto a, auto b) {
hero.say("The naive algorithm.");
auto cycles = 0;
// We enumerate all possible divisors.
auto counter = b;
while (true) {
cycles++;
if (cycles > 100) {
hero.say("Calculating is hard. I'm tired.");
break;
}
// If both number have "counter" divisor.
if (a % counter == 0 && b % counter == 0) {
break;
}
counter--;
}
hero.say("I used " + cycles + " cycles");
return counter;
}
auto euclidianGCD (auto a, auto b) {
auto cycles = 0;
while (b) {
cycles++;
auto swap = b;
b = a % b;
a = swap;
}
hero.say("I used " + cycles + " cycles");
return a;
}
int main() {
// Maybe you need to use another function?
auto secretNumber = euclidianGCD(number1, number2); // ∆
hero.moveXY(48, 34);
hero.say(secretNumber);
// The treasury is open (I hope so)! Go there!
hero.moveXY(68, 34);
return 0;
}