In: Computer Science
The Golomb's sequence is G(n) = 1 + G(n - G(G(n - 1)))
For what n value (approximately) does your computer stop producing output? Why is this?
The following is my code, but I don't know what would be the max value for n, since my computer stuck at 80
#include <iostream>
using namespace std;
int golombSequence(int);
int golombSequence(int max){
if(max == 1){
return 1;
}
else{
return 1 + golombSequence(max - golombSequence(golombSequence(max-1)));
}
}
int main(int argc, const char * argv[]) {
// int n = 90;
// for(int i = 1; i<=n; i++){
// cout<<i<<": "<<golombSequence(i)<<endl;
// }
// return 0;
}
C++ Program:
Output:
Hence, this is the reason why the program is hunging up your system and the maximum will depend on the systems capacity and the input of the program.