Eydeet
0
Mein Ansatz für Problem 14 scheint nicht die richtige Lösung auszugeben. Vielleicht findet ja jemand den Fehler:
Code:
#include <iostream>
using namespace std;
int main() {
int test, i, tmp, max=0, top=0;
for(test=0; test < 1000000; test++) {
//cout << test;
i = 1;
tmp = test;
while(tmp > 1) {
if(tmp % 2 == 0) {
tmp /= 2;
//cout << "->" << tmp;
} else {
tmp = 3 * tmp + 1;
//cout << "->" << tmp;
}
i++;
}
if(i>=max) {
max=i;
top=test;
cout << top << ": " << max << endl;
}
//cout << " = " << i << endl;
i = 0;
}
cout << endl << "Longest chain: " << top << ": " << max << endl;
}