14 #include <unordered_set> 25 if (mask == 4294967295u) {
27 }
else if (mask == 18446744073709551615ull) {
32 const value_type verbose_mask(mask > (static_cast<value_type>(1) << 26) - 1
33 ? (static_cast<value_type>(1) << 26) - 1
37 std::set<value_type> exceptions;
38 std::unordered_set<value_type> visited_values;
43 if (verbose_mask != 0) {
49 for (
value_type start_n(1); start_n <= mask; start_n += 2) {
53 if ((start_n & verbose_mask) == 1) {
54 std::cerr <<
' ' << start_n;
66 if (!visited_values.insert(n).second) {
70 }
while (n > start_n);
72 visited_values.clear();
74 if (exceptions.find(n) != exceptions.cend()) {
75 exceptions.insert(start_n);
78 std::cerr <<
"* Exception: " << start_n <<
"*";
85 if (verbose_mask != 0) {
86 std::cerr <<
']' << std::endl;
97 assert(std::numeric_limits<value_type>::digits >= 32);
100 const value_type verbose_mask((static_cast<value_type>(1) << 26) - 1);
103 std::set<value_type> exceptions;
104 std::unordered_set<value_type> visited_values;
106 exceptions.insert(0);
113 for (uint32_t start_n(3); start_n != 1; start_n += 2) {
117 if ((start_n & verbose_mask) == 1) {
118 std::cerr <<
' ' << start_n;
124 assert((n & 1) != 0);
130 if (!visited_values.insert(n).second) {
134 }
while (n > start_n);
136 visited_values.clear();
138 if (exceptions.find(n) != exceptions.cend()) {
139 exceptions.insert(start_n);
142 std::cerr <<
"* Exception: " << start_n <<
"*";
149 std::cerr <<
']' << std::endl;
159 assert(std::numeric_limits<value_type>::digits >= 64);
162 const value_type verbose_mask((static_cast<value_type>(1) << 26) - 1);
165 std::set<value_type> exceptions;
166 std::unordered_set<value_type> visited_values;
168 exceptions.insert(0);
175 for (uint64_t start_n(3); start_n != 1; start_n += 2) {
179 if ((start_n & verbose_mask) == 1) {
180 std::cerr <<
' ' << start_n;
186 assert((n & 1) != 0);
192 if (!visited_values.insert(n).second) {
196 }
while (n > start_n);
198 visited_values.clear();
200 if (exceptions.find(n) != exceptions.cend()) {
201 exceptions.insert(start_n);
204 std::cerr <<
"* Exception: " << start_n <<
"*";
211 std::cerr <<
']' << std::endl;
219 std::vector<value_type>
226 std::vector<value_type> path{n};
227 std::unordered_set<value_type> visited_values;
229 while ((n >= start_n) && visited_values.insert(n).second) {
230 n = operation_mask(n, mask);
value_type m2(value_type n)
function.
std::vector< value_type > start_path_mask(value_type n, operation_mask_type operation_mask, value_type mask)
Given operation, return the start of path from n to the first value < n or to the first repeated valu...
std::set< value_type > search_mask_exceptions_32()
Calculate and return all null and odd exceptions for the 3n + 1 problem with modulo ...
value_type(* operation_mask_type)(value_type, value_type)
std::set< value_type > search_mask_exceptions_64()
Calculate and return all null and odd exceptions for the 3n + 1 problem with modulo ...
std::set< value_type > search_mask_exceptions(value_type mask)
Calculate and return all null and odd exceptions for the 3n + 1 problem with modulo (mask + 1)...