Simple tool to brute force 3x+1 for a new loop.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Create the first basic app

BuyMyMojo dc541524

+565
+1
.gitignore
··· 1 + /target
+8
.idea/.gitignore
··· 1 + # Default ignored files 2 + /shelf/ 3 + /workspace.xml 4 + # Editor-based HTTP Client requests 5 + /httpRequests/ 6 + # Datasource local storage ignored files 7 + /dataSources/ 8 + /dataSources.local.xml
+7
.idea/discord.xml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <project version="4"> 3 + <component name="DiscordProjectSettings"> 4 + <option name="show" value="ASK" /> 5 + <option name="description" value="" /> 6 + </component> 7 + </project>
+8
.idea/modules.xml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <project version="4"> 3 + <component name="ProjectModuleManager"> 4 + <modules> 5 + <module fileurl="file://$PROJECT_DIR$/.idea/rust-3xp1.iml" filepath="$PROJECT_DIR$/.idea/rust-3xp1.iml" /> 6 + </modules> 7 + </component> 8 + </project>
+12
.idea/rust-3xp1.iml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <module type="WEB_MODULE" version="4"> 3 + <component name="Go" enabled="true" /> 4 + <component name="NewModuleRootManager"> 5 + <content url="file://$MODULE_DIR$"> 6 + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> 7 + <excludeFolder url="file://$MODULE_DIR$/target" /> 8 + </content> 9 + <orderEntry type="inheritedJdk" /> 10 + <orderEntry type="sourceFolder" forTests="false" /> 11 + </component> 12 + </module>
+6
.idea/vcs.xml
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <project version="4"> 3 + <component name="VcsDirectoryMappings"> 4 + <mapping directory="$PROJECT_DIR$" vcs="Git" /> 5 + </component> 6 + </project>
+364
Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 3 4 + 5 + [[package]] 6 + name = "ansi_term" 7 + version = "0.12.1" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" 10 + dependencies = [ 11 + "winapi", 12 + ] 13 + 14 + [[package]] 15 + name = "atty" 16 + version = "0.2.14" 17 + source = "registry+https://github.com/rust-lang/crates.io-index" 18 + checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 19 + dependencies = [ 20 + "hermit-abi", 21 + "libc", 22 + "winapi", 23 + ] 24 + 25 + [[package]] 26 + name = "autocfg" 27 + version = "1.1.0" 28 + source = "registry+https://github.com/rust-lang/crates.io-index" 29 + checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 30 + 31 + [[package]] 32 + name = "bitflags" 33 + version = "1.3.2" 34 + source = "registry+https://github.com/rust-lang/crates.io-index" 35 + checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 36 + 37 + [[package]] 38 + name = "cfg-if" 39 + version = "1.0.0" 40 + source = "registry+https://github.com/rust-lang/crates.io-index" 41 + checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 42 + 43 + [[package]] 44 + name = "clap" 45 + version = "3.1.5" 46 + source = "registry+https://github.com/rust-lang/crates.io-index" 47 + checksum = "ced1892c55c910c1219e98d6fc8d71f6bddba7905866ce740066d8bfea859312" 48 + dependencies = [ 49 + "atty", 50 + "bitflags", 51 + "clap_derive", 52 + "indexmap", 53 + "lazy_static", 54 + "os_str_bytes", 55 + "strsim", 56 + "termcolor", 57 + "textwrap", 58 + ] 59 + 60 + [[package]] 61 + name = "clap_derive" 62 + version = "3.1.4" 63 + source = "registry+https://github.com/rust-lang/crates.io-index" 64 + checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" 65 + dependencies = [ 66 + "heck", 67 + "proc-macro-error", 68 + "proc-macro2", 69 + "quote", 70 + "syn", 71 + ] 72 + 73 + [[package]] 74 + name = "hashbrown" 75 + version = "0.11.2" 76 + source = "registry+https://github.com/rust-lang/crates.io-index" 77 + checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" 78 + 79 + [[package]] 80 + name = "heck" 81 + version = "0.4.0" 82 + source = "registry+https://github.com/rust-lang/crates.io-index" 83 + checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" 84 + 85 + [[package]] 86 + name = "hermit-abi" 87 + version = "0.1.19" 88 + source = "registry+https://github.com/rust-lang/crates.io-index" 89 + checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 90 + dependencies = [ 91 + "libc", 92 + ] 93 + 94 + [[package]] 95 + name = "indexmap" 96 + version = "1.8.0" 97 + source = "registry+https://github.com/rust-lang/crates.io-index" 98 + checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" 99 + dependencies = [ 100 + "autocfg", 101 + "hashbrown", 102 + ] 103 + 104 + [[package]] 105 + name = "lazy_static" 106 + version = "1.4.0" 107 + source = "registry+https://github.com/rust-lang/crates.io-index" 108 + checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 109 + 110 + [[package]] 111 + name = "libc" 112 + version = "0.2.119" 113 + source = "registry+https://github.com/rust-lang/crates.io-index" 114 + checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" 115 + 116 + [[package]] 117 + name = "log" 118 + version = "0.4.14" 119 + source = "registry+https://github.com/rust-lang/crates.io-index" 120 + checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 121 + dependencies = [ 122 + "cfg-if", 123 + ] 124 + 125 + [[package]] 126 + name = "memchr" 127 + version = "2.4.1" 128 + source = "registry+https://github.com/rust-lang/crates.io-index" 129 + checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 130 + 131 + [[package]] 132 + name = "once_cell" 133 + version = "1.10.0" 134 + source = "registry+https://github.com/rust-lang/crates.io-index" 135 + checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" 136 + 137 + [[package]] 138 + name = "os_str_bytes" 139 + version = "6.0.0" 140 + source = "registry+https://github.com/rust-lang/crates.io-index" 141 + checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" 142 + dependencies = [ 143 + "memchr", 144 + ] 145 + 146 + [[package]] 147 + name = "pin-project-lite" 148 + version = "0.2.8" 149 + source = "registry+https://github.com/rust-lang/crates.io-index" 150 + checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" 151 + 152 + [[package]] 153 + name = "proc-macro-error" 154 + version = "1.0.4" 155 + source = "registry+https://github.com/rust-lang/crates.io-index" 156 + checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 157 + dependencies = [ 158 + "proc-macro-error-attr", 159 + "proc-macro2", 160 + "quote", 161 + "syn", 162 + "version_check", 163 + ] 164 + 165 + [[package]] 166 + name = "proc-macro-error-attr" 167 + version = "1.0.4" 168 + source = "registry+https://github.com/rust-lang/crates.io-index" 169 + checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 170 + dependencies = [ 171 + "proc-macro2", 172 + "quote", 173 + "version_check", 174 + ] 175 + 176 + [[package]] 177 + name = "proc-macro2" 178 + version = "1.0.36" 179 + source = "registry+https://github.com/rust-lang/crates.io-index" 180 + checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 181 + dependencies = [ 182 + "unicode-xid", 183 + ] 184 + 185 + [[package]] 186 + name = "quote" 187 + version = "1.0.15" 188 + source = "registry+https://github.com/rust-lang/crates.io-index" 189 + checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" 190 + dependencies = [ 191 + "proc-macro2", 192 + ] 193 + 194 + [[package]] 195 + name = "rust-3xp1" 196 + version = "1.0.0" 197 + dependencies = [ 198 + "clap", 199 + "tracing", 200 + "tracing-subscriber", 201 + ] 202 + 203 + [[package]] 204 + name = "sharded-slab" 205 + version = "0.1.4" 206 + source = "registry+https://github.com/rust-lang/crates.io-index" 207 + checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" 208 + dependencies = [ 209 + "lazy_static", 210 + ] 211 + 212 + [[package]] 213 + name = "smallvec" 214 + version = "1.8.0" 215 + source = "registry+https://github.com/rust-lang/crates.io-index" 216 + checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" 217 + 218 + [[package]] 219 + name = "strsim" 220 + version = "0.10.0" 221 + source = "registry+https://github.com/rust-lang/crates.io-index" 222 + checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 223 + 224 + [[package]] 225 + name = "syn" 226 + version = "1.0.86" 227 + source = "registry+https://github.com/rust-lang/crates.io-index" 228 + checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" 229 + dependencies = [ 230 + "proc-macro2", 231 + "quote", 232 + "unicode-xid", 233 + ] 234 + 235 + [[package]] 236 + name = "termcolor" 237 + version = "1.1.3" 238 + source = "registry+https://github.com/rust-lang/crates.io-index" 239 + checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 240 + dependencies = [ 241 + "winapi-util", 242 + ] 243 + 244 + [[package]] 245 + name = "textwrap" 246 + version = "0.15.0" 247 + source = "registry+https://github.com/rust-lang/crates.io-index" 248 + checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" 249 + 250 + [[package]] 251 + name = "thread_local" 252 + version = "1.1.4" 253 + source = "registry+https://github.com/rust-lang/crates.io-index" 254 + checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" 255 + dependencies = [ 256 + "once_cell", 257 + ] 258 + 259 + [[package]] 260 + name = "tracing" 261 + version = "0.1.31" 262 + source = "registry+https://github.com/rust-lang/crates.io-index" 263 + checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f" 264 + dependencies = [ 265 + "cfg-if", 266 + "pin-project-lite", 267 + "tracing-attributes", 268 + "tracing-core", 269 + ] 270 + 271 + [[package]] 272 + name = "tracing-attributes" 273 + version = "0.1.19" 274 + source = "registry+https://github.com/rust-lang/crates.io-index" 275 + checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" 276 + dependencies = [ 277 + "proc-macro2", 278 + "quote", 279 + "syn", 280 + ] 281 + 282 + [[package]] 283 + name = "tracing-core" 284 + version = "0.1.22" 285 + source = "registry+https://github.com/rust-lang/crates.io-index" 286 + checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23" 287 + dependencies = [ 288 + "lazy_static", 289 + "valuable", 290 + ] 291 + 292 + [[package]] 293 + name = "tracing-log" 294 + version = "0.1.2" 295 + source = "registry+https://github.com/rust-lang/crates.io-index" 296 + checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" 297 + dependencies = [ 298 + "lazy_static", 299 + "log", 300 + "tracing-core", 301 + ] 302 + 303 + [[package]] 304 + name = "tracing-subscriber" 305 + version = "0.3.9" 306 + source = "registry+https://github.com/rust-lang/crates.io-index" 307 + checksum = "9e0ab7bdc962035a87fba73f3acca9b8a8d0034c2e6f60b84aeaaddddc155dce" 308 + dependencies = [ 309 + "ansi_term", 310 + "sharded-slab", 311 + "smallvec", 312 + "thread_local", 313 + "tracing-core", 314 + "tracing-log", 315 + ] 316 + 317 + [[package]] 318 + name = "unicode-xid" 319 + version = "0.2.2" 320 + source = "registry+https://github.com/rust-lang/crates.io-index" 321 + checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 322 + 323 + [[package]] 324 + name = "valuable" 325 + version = "0.1.0" 326 + source = "registry+https://github.com/rust-lang/crates.io-index" 327 + checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" 328 + 329 + [[package]] 330 + name = "version_check" 331 + version = "0.9.4" 332 + source = "registry+https://github.com/rust-lang/crates.io-index" 333 + checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 334 + 335 + [[package]] 336 + name = "winapi" 337 + version = "0.3.9" 338 + source = "registry+https://github.com/rust-lang/crates.io-index" 339 + checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 340 + dependencies = [ 341 + "winapi-i686-pc-windows-gnu", 342 + "winapi-x86_64-pc-windows-gnu", 343 + ] 344 + 345 + [[package]] 346 + name = "winapi-i686-pc-windows-gnu" 347 + version = "0.4.0" 348 + source = "registry+https://github.com/rust-lang/crates.io-index" 349 + checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 350 + 351 + [[package]] 352 + name = "winapi-util" 353 + version = "0.1.5" 354 + source = "registry+https://github.com/rust-lang/crates.io-index" 355 + checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 356 + dependencies = [ 357 + "winapi", 358 + ] 359 + 360 + [[package]] 361 + name = "winapi-x86_64-pc-windows-gnu" 362 + version = "0.4.0" 363 + source = "registry+https://github.com/rust-lang/crates.io-index" 364 + checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+11
Cargo.toml
··· 1 + [package] 2 + name = "rust-3xp1" 3 + version = "1.0.0" 4 + edition = "2021" 5 + 6 + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 + 8 + [dependencies] 9 + tracing = "0.1.31" 10 + tracing-subscriber = "0.3.9" 11 + clap = { version = "3.1.5", features = ["derive"] }
+148
src/main.rs
··· 1 + use std::ops::Mul; 2 + use std::process::exit; 3 + use tracing::{Level, instrument, event}; 4 + use tracing_subscriber; 5 + use clap::Parser; 6 + 7 + /// Simple program to greet a person 8 + #[derive(Parser, Debug)] 9 + #[clap(author, version, about, long_about = None)] 10 + struct Args { 11 + /// Weather to output current number each time 12 + #[clap(short, long)] 13 + verbose: bool, 14 + 15 + /// Weather to output current number every step of 3x+1 16 + #[clap(short, long)] 17 + double_verbose: bool, 18 + 19 + /// Number of times to try 20 + #[clap(short, long, default_value_t = 50000)] 21 + count: u128, 22 + 23 + /// Number to start at 24 + #[clap(short, long, default_value_t = 195147905179352825856)] 25 + start: u128, 26 + } 27 + 28 + #[instrument] 29 + fn main() { 30 + tracing_subscriber::fmt::init(); 31 + let args = Args::parse(); 32 + 33 + let max_num = args.start + args.count; 34 + 35 + event!(Level::INFO, "Starting 3x+1 process"); 36 + event!(Level::INFO, "Starting number: {}", args.start); 37 + event!(Level::INFO, "Amount of numbers to try: {}", args.count); 38 + 39 + if args.verbose{ 40 + for current_num in args.start..max_num{ 41 + event!(Level::INFO, "Processing {}", current_num); 42 + let (smallest_num, largest_num) = txpo(current_num); 43 + event!(Level::INFO, "Loop found! Smallest number: {}, largest number: {}", smallest_num, largest_num); 44 + } 45 + } else if args.double_verbose { 46 + for current_num in args.start..max_num{ 47 + event!(Level::INFO, "Processing {}", current_num); 48 + let (smallest_num, largest_num) = verbose_txpo(current_num); 49 + event!(Level::INFO, "Loop found! Smallest number: {}, largest number: {}", smallest_num, largest_num); 50 + } 51 + } else { 52 + for current_num in args.start..max_num{ 53 + let (_smallest_num, _largest_num) = txpo(current_num); 54 + } 55 + } 56 + 57 + event!(Level::INFO, "Finished trying {} numbers", args.count); 58 + } 59 + 60 + #[instrument] 61 + fn txpo(mut current_num: u128) -> (u128, u128) { 62 + let mut largest_num = current_num; 63 + let mut smallest_num = current_num; 64 + let mut smallest_num_count = 1; 65 + while smallest_num_count != 2{ 66 + 67 + // if odd 68 + if current_num % 2 != 0 { 69 + if current_num < smallest_num{ 70 + smallest_num = current_num; 71 + } 72 + 73 + if current_num > largest_num{ 74 + largest_num = current_num; 75 + } 76 + 77 + current_num = current_num.mul(3) + 1; // For some reason using .mul() is faster then * but .add() is slightly slower then +. it was only a few ms slower to do all 50K but on an extremely large scale it matters 78 + } else { 79 + if current_num < smallest_num{ 80 + smallest_num = current_num; 81 + } 82 + 83 + if current_num > largest_num{ 84 + largest_num = current_num; 85 + } 86 + 87 + current_num = current_num >> 1; // Divides by 2 a bit faster 88 + } 89 + 90 + if current_num == smallest_num { 91 + smallest_num_count = smallest_num_count + 1; 92 + } 93 + } 94 + 95 + if smallest_num != 1{ 96 + event!(Level::ERROR, "Found new loop!"); 97 + exit(1) 98 + } 99 + 100 + return(smallest_num, largest_num); 101 + } 102 + 103 + #[instrument] 104 + fn verbose_txpo(mut current_num: u128) -> (u128, u128) { 105 + let mut largest_num = current_num; 106 + let mut smallest_num = current_num; 107 + let mut smallest_num_count = 1; 108 + while smallest_num_count != 2{ 109 + 110 + // if odd 111 + if current_num % 2 != 0 { 112 + if current_num < smallest_num{ 113 + smallest_num = current_num; 114 + } 115 + 116 + if current_num > largest_num{ 117 + largest_num = current_num; 118 + } 119 + 120 + event!(Level::INFO, "{} is odd. Smallest number: {}. Largest number: {}", current_num, smallest_num, largest_num); 121 + 122 + current_num = current_num.mul(3) + 1; // For some reason using .mul() is faster then * but .add() is slightly slower then +. it was only a few ms slower to do all 50K but on an extremely large scale it matters 123 + } else { 124 + if current_num < smallest_num{ 125 + smallest_num = current_num; 126 + } 127 + 128 + if current_num > largest_num{ 129 + largest_num = current_num; 130 + } 131 + 132 + event!(Level::INFO, "{} is even. Smallest number: {}. Largest number: {}", current_num, smallest_num, largest_num); 133 + 134 + current_num = current_num >> 1; // Divides by 2 a bit faster 135 + } 136 + 137 + if current_num == smallest_num { 138 + smallest_num_count = smallest_num_count + 1; 139 + } 140 + } 141 + 142 + if smallest_num != 1{ 143 + event!(Level::ERROR, "Found new loop!"); 144 + exit(1) 145 + } 146 + 147 + return(smallest_num, largest_num); 148 + }