Skip to content

Instantly share code, notes, and snippets.

@dwurf
Created January 13, 2016 10:00
Show Gist options
  • Save dwurf/070945cf2b06a537cae2 to your computer and use it in GitHub Desktop.
Save dwurf/070945cf2b06a537cae2 to your computer and use it in GitHub Desktop.
Program to solve cyclobs' weird problem
#include <iostream>
#include <cstdlib>
using namespace std;
// Arbitrary precision c++ library
// compile with:
// gcc thisfile.c -lgmp -lgmpxx -o mybinary
#include <gmpxx.h>
int main(int argc, char **argv){
if (argc < 2) {
cout << "Please give me a number!" << endl;
cout << "Usage: " << argv[0] << " <number>" << endl;
exit(1);
}
mpz_class num;
try {
num = argv[1];
} catch (invalid_argument) {
cout << "That wasn't a number dipshit" << endl;
exit(1);
}
unsigned int i = 0;
while (num != 1) {
if (num % 1 == 0) {
num /= 2;
} else {
num = num * 3 + 1;
}
i += 1;
}
cout << "Found 1 in " << i << " iterations." << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment