Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I wrote some code to work in reverse, starting with a target number and going (ideally) down until 1 was reached. (In retrospect, I didn't get the reverse spelling completely correct; sorry! I imagine my version pronounced with a Spanish accent and sounding like "yoke toss.")
- I realized that if the numbers got bigger and bigger, I'd have a halting problem-like problem to deal with. So, I just hoped that they'd end up hitting a loop (like 1 -> 4 -> 2 -> 1, if the problem didn't end with 1). I guess I'd know something was up when my computer spewed out of memory errors if it just kept going higher and higher. Anyway, my code:
- def lloctaz(n, verbose=False):
- seen = {n}
- while n != 1:
- if verbose: print(n, end=' ')
- if n % 2 == 0:
- if verbose: print('/ 2 =')
- n = n // 2
- else:
- if verbose: print('* 3 + 1 =')
- n = n * 3 + 1
- if n in seen:
- print(n, '<-- !!! CYCLE DETECTED !!!')
- return False
- else:
- seen.add(n)
- if verbose: print(1)
- return len(seen)
- def test(start):
- while lloctaz(start):
- start += 1
- if start % 1_000_000 == 0:
- print(start)
- I let this run until I reached a cycle -- it took a *lot* longer than I expected.
- >>> test(1)
- 1000000
- 2000000
- 3000000
- [... big snip ...]
- 57677621523618000000
- 57677621523619000000
- 57677621523620000000
- 57677621523620152583 <-- !!! CYCLE DETECTED !!!
- >>>
- I investigated:
- >>> lloctaz(57677621523620152583, True)
- 57677621523620152583 * 3 + 1 =
- 173032864570860457750 / 2 =
- 86516432285430228875 * 3 + 1 =
- 259549296856290686626 / 2 =
- 129774648428145343313 * 3 + 1 =
- 378914162223842065210 / 2 =
- 189457081111921032605 * 3 + 1 =
- 568371243335763097816 / 2 =
- 284185621667881548908 / 2 =
- 142092810833940774454 / 2 =
- 71046405416970387227 * 3 + 1 =
- 213139216250911161682 / 2 =
- 106569608125455580841 * 3 + 1 =
- 319708824376366742524 / 2 =
- 159854412188183371262 / 2 =
- 79927206094091685631 * 3 + 1 =
- 239781618282275056894 / 2 =
- 119890809141137528447 * 3 + 1 =
- 359672427423412585342 / 2 =
- 179836213711706292671 * 3 + 1 =
- 539508641135118878014 / 2 =
- 269754320567559439007 * 3 + 1 =
- 809262961702678317022 / 2 =
- 404631480851339158511 * 3 + 1 =
- 1213894442554017475534 / 2 =
- 606947221277008737767 * 3 + 1 =
- 1820841663831026213302 / 2 =
- 910420831915513106651 * 3 + 1 =
- 2731262495746539319954 / 2 =
- 1365631247873269659977 * 3 + 1 =
- 4096893743619808979932 / 2 =
- 2048446871809904489966 / 2 =
- 1024223435904952244983 * 3 + 1 =
- 3072670307714856734950 / 2 =
- 1536335153857428367475 * 3 + 1 =
- 4609005461572285102426 / 2 =
- 2304502730786142551213 * 3 + 1 =
- 6913508192358427653640 / 2 =
- 3456754096179213826820 / 2 =
- 1728377048089606913410 / 2 =
- 864188524044803456705 * 3 + 1 =
- 2592565572134410370116 / 2 =
- 1296282786067205185058 / 2 =
- 648141393033602592529 * 3 + 1 =
- 1944424179100807777588 / 2 =
- 972212089550403888794 / 2 =
- 486106044775201944397 * 3 + 1 =
- 1458318134325605833192 / 2 =
- 729159067162802916596 / 2 =
- 364579533581401458298 / 2 =
- 182289766790700729149 * 3 + 1 =
- 546869300372102187448 / 2 =
- 273434650186051093724 / 2 =
- 136717325093025546862 / 2 =
- 68358662546512773431 * 3 + 1 =
- 205075987639538320294 / 2 =
- 102537993819769160147 * 3 + 1 =
- 307613981459307480442 / 2 =
- 153806990729653740221 * 3 + 1 =
- 461420972188961220664 / 2 =
- 230710486094480610332 / 2 =
- 115355243047240305166 / 2 =
- 57677621523620152583 <-- !!! CYCLE DETECTED !!!
- False
- >>>
- I couldn't find the sequence in OEIS; for that matter, I couldn't find *any* of the numbers in OEIS. I didn't get any hits for 57677621523620152583 on Google, either, but I imagine they'll come once people start solving this. Wolfram|Alpha gave its prime factorization as 79 × 103 × 541 × 571 × 22946140769, which doesn't seem to be super insightful.
- I do like how the numbers went up and down like that -- there's something soothing, yet chaotic about that procedure.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement