1- #include < args_handle.hxx>
2- #include < collatz_matrix.hxx>
3- #include < exception>
4- #include < iomanip>
1+ #include < collatz_path.hxx>
52#include < iostream>
6- #include < stdexcept>
73#include < string>
8- #include < unordered_map>
94
10- int main ( int argc, const char **argv ) {
5+ void print_help ( ) {
116 using namespace std ;
12- unordered_map<string, string> args;
13- args = get_args (argc, argv);
14- uint64_t highestOddStarter = 0 , longestPath = 0 , seed = 0 ;
15- if (args.empty () || args.find (" help" ) != args.end () || args.find (" h" ) != args.end ()) return 0 ;
16-
17- try {
18- highestOddStarter = stoull (args.at (" highestOddStarter" ));
19- seed = stoull (args.at (" seed" ));
20- longestPath = stoull (args.at (" longestPath" ));
21- } catch (const out_of_range &ofer) { cout << ofer.what () << endl; }
22-
23- try {
24- CollatzMatrix colMat (highestOddStarter, longestPath);
25- vector<Vec4<uint64_t >> path = std::move (colMat.find_path (seed));
26-
27- if (args.find (" debug" ) != args.end () && args.at (" debug" ) == " true" ) colMat.printMatrices ();
28-
29- for (auto val : path)
30- cout << setw (10 ) << " Matrix index = " << val.w << setw (10 ) << " row = " << val.x << setw (10 ) << " col = " << val.y << setw (10 ) << " value = " << val.z
31- << endl;
32- cout << endl << " Real Path on the original collatz function =" ;
33- for (auto val : path) cout << 2 * val.z - 1 << " " ;
34- cout << endl;
35- } catch (const exception &e) { cout << e.what () << endl; }
7+ cout << " -s or --seed to set the seed" << endl;
8+ cout << " -e or --exp to activate expMode" << endl << " \t when the next argument passed as integer, it will be setted as 2^seed*odd -1" ;
9+ }
3610
11+ int main (int argc, const char **argv) {
12+ using namespace std ;
13+ if (argc < 3 ) print_help ();
14+ uint64_t seed = 0 , odd = 1 ;
15+ bool expMode = false ;
16+ for (int i = 1 ; i < argc; ++i) {
17+ if ((string (argv[i]) == " -s" || string (argv[i]) == " --seed" ) && argc > i + 1 ) seed = stoull (argv[i + 1 ]);
18+ if ((string (argv[i]) == " -e" || string (argv[i]) == " --exp" )) {
19+ expMode = true ;
20+ if (argc > i + 1 ) odd = stoull (string (argv[i + 1 ]));
21+ }
22+ }
23+ if (seed == 0 ) {
24+ print_help ();
25+ return -1 ;
26+ }
27+ vector<uint64_t > result;
28+ if (expMode) {
29+ seed = int_pow<uint64_t >(2 , seed) * odd - 1 ;
30+ result = collatz_get_path (seed);
31+ } else result = collatz_get_path (seed);
32+ cout << " path for " << seed << " =" ;
33+ for (auto val : result) cout << " " << val;
34+ cout << endl;
3735 return 0 ;
3836}
0 commit comments