I managed to make a simple function that calculates the Hailstone sequence of numbers and print it out, and I just done a calculator that grabs the number with the largest sequence smaller than n
— and it may disprove the Collatz conjecture.
Code with input numbers:
#include <iostream>
#include <string>
using namespace std;
void parseSequence(long n, long o) {
long m = n;
if (m % 2 == 0) {
m /= 2;
}
else if (m != 1) {
m *= 3;
m++;
}
cout << m << endl;
if (m == 1) {
cout << "End of sequence! (sequence's lenght is " << o << ")." << endl;
}
else {
o++;
parseSequence(m, o);
}
}
int main() {
string p;
long n;
cout << "\nWhich is the number to calculate the Hailstone sequence?\n";
cin >> n;
parseSequence(n, 1);
cout << "Parse more sequence?\n\n(y|n)\n\n:";
cin >> p;
if (p == "y" or p == "Y") {
return main();
}
else return 0;
}
Calculator that displays number's largest sequence lenght with it's sequence's lenght:
#include <iostream>
#include <string>
using namespace std;
int parseSequence(long n, long o) {
long m = n;
if (m % 2 == 0) {
m /= 2;
}
else if (m != 1) {
m *= 3;
m++;
}
cout << m << endl;
if (m == 1) {
cout << "End of sequence! (sequence's lenght is " << o << ")." << endl;
return o;
}
else {
o++;
return parseSequence(m, o);
}
}
int main() {
string p;
long n;
cout << "\nWhich is the max number to calculate the longest sequence?\n";
cin >> n;
long l;
long q;
long y;
long i;
q = 0;
for ( i = 1; i <= n; i++) {
l = parseSequence(i, 0);
if (l > q) {
q = l;
y = i;
}
}
cout << "The number with the largest sequence : It's sequence's lenght = " << y << " : " << q;
return 0;
}
I call the last one Project LightyMoon.
n
and then calculaten*3+1
. Oops. Collatz is safe. \$\endgroup\$