Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
6fb0e7acd9 | |||
9e21df19cd |
@ -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.
|
||||
|
5
main.cpp
5
main.cpp
@ -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';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user