Compare commits

..

2 Commits
2.0 ... master

Author SHA1 Message Date
6fb0e7acd9 Print amount of steps at the end 2024-07-13 12:11:26 -07:00
9e21df19cd Update README.md to show releases 2024-07-08 09:13:22 -07:00
2 changed files with 8 additions and 0 deletions

View File

@ -7,6 +7,9 @@ To build:
- With GMP: Run `make -j1` (any more than `-j1` doesn't really do anything, there's four things to do and they can't be put out of order).
- Without GMP: Run `make gmpless -j1` (see above parenthetical statement).
You can get releases at [here](https://git.sdf.org/ilikecats/collatz/releases), but only GMP releases (except for 1.0), and only for GNU/Linux (except for 1.0).
You have to build without GMP if you don't want to/can't use GMP.
Algorithm:
- Start with number.
- If number is even, divide by two.

View File

@ -29,12 +29,15 @@ int main(int argc, char* argv[]) {
}
mpz_t x; // mpz_t is the GMP equiv. of int
mpz_t xmod2; // Store x % 2
mpz_t steps; // Steps taken to get to one
// Init vars (if not disabled init)
#ifndef GMPLESS
mpz_init_set_str(x, argv[1],10);
mpz_init(xmod2);
mpz_init(steps);
#else
x = std::stoll(argv[1]);
steps = 0;
#endif
// Output x
std::cout << x << '\n'; // impacted section of code
@ -47,6 +50,8 @@ int main(int argc, char* argv[]) {
mpz_mul_ui(x,x,3); // x *= 3
mpz_add_ui(x,x,1); // x += 1
}
mpz_add_ui(steps,steps,1); // steps += 1
std::cout << x << '\n';
}
std::cout << "Steps: " << steps << '\n';
}