Advertisement
Guest User

Joker Classic 2022-04-01: Collatz In Sunbeams

a guest
Apr 3rd, 2022
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. 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.")
  2.  
  3. 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:
  4.  
  5. def lloctaz(n, verbose=False):
  6. seen = {n}
  7. while n != 1:
  8. if verbose: print(n, end=' ')
  9. if n % 2 == 0:
  10. if verbose: print('/ 2 =')
  11. n = n // 2
  12. else:
  13. if verbose: print('* 3 + 1 =')
  14. n = n * 3 + 1
  15. if n in seen:
  16. print(n, '<-- !!! CYCLE DETECTED !!!')
  17. return False
  18. else:
  19. seen.add(n)
  20. if verbose: print(1)
  21. return len(seen)
  22.  
  23. def test(start):
  24. while lloctaz(start):
  25. start += 1
  26. if start % 1_000_000 == 0:
  27. print(start)
  28.  
  29. I let this run until I reached a cycle -- it took a *lot* longer than I expected.
  30. >>> test(1)
  31. 1000000
  32. 2000000
  33. 3000000
  34. [... big snip ...]
  35. 57677621523618000000
  36. 57677621523619000000
  37. 57677621523620000000
  38. 57677621523620152583 <-- !!! CYCLE DETECTED !!!
  39. >>>
  40.  
  41. I investigated:
  42. >>> lloctaz(57677621523620152583, True)
  43. 57677621523620152583 * 3 + 1 =
  44. 173032864570860457750 / 2 =
  45. 86516432285430228875 * 3 + 1 =
  46. 259549296856290686626 / 2 =
  47. 129774648428145343313 * 3 + 1 =
  48. 378914162223842065210 / 2 =
  49. 189457081111921032605 * 3 + 1 =
  50. 568371243335763097816 / 2 =
  51. 284185621667881548908 / 2 =
  52. 142092810833940774454 / 2 =
  53. 71046405416970387227 * 3 + 1 =
  54. 213139216250911161682 / 2 =
  55. 106569608125455580841 * 3 + 1 =
  56. 319708824376366742524 / 2 =
  57. 159854412188183371262 / 2 =
  58. 79927206094091685631 * 3 + 1 =
  59. 239781618282275056894 / 2 =
  60. 119890809141137528447 * 3 + 1 =
  61. 359672427423412585342 / 2 =
  62. 179836213711706292671 * 3 + 1 =
  63. 539508641135118878014 / 2 =
  64. 269754320567559439007 * 3 + 1 =
  65. 809262961702678317022 / 2 =
  66. 404631480851339158511 * 3 + 1 =
  67. 1213894442554017475534 / 2 =
  68. 606947221277008737767 * 3 + 1 =
  69. 1820841663831026213302 / 2 =
  70. 910420831915513106651 * 3 + 1 =
  71. 2731262495746539319954 / 2 =
  72. 1365631247873269659977 * 3 + 1 =
  73. 4096893743619808979932 / 2 =
  74. 2048446871809904489966 / 2 =
  75. 1024223435904952244983 * 3 + 1 =
  76. 3072670307714856734950 / 2 =
  77. 1536335153857428367475 * 3 + 1 =
  78. 4609005461572285102426 / 2 =
  79. 2304502730786142551213 * 3 + 1 =
  80. 6913508192358427653640 / 2 =
  81. 3456754096179213826820 / 2 =
  82. 1728377048089606913410 / 2 =
  83. 864188524044803456705 * 3 + 1 =
  84. 2592565572134410370116 / 2 =
  85. 1296282786067205185058 / 2 =
  86. 648141393033602592529 * 3 + 1 =
  87. 1944424179100807777588 / 2 =
  88. 972212089550403888794 / 2 =
  89. 486106044775201944397 * 3 + 1 =
  90. 1458318134325605833192 / 2 =
  91. 729159067162802916596 / 2 =
  92. 364579533581401458298 / 2 =
  93. 182289766790700729149 * 3 + 1 =
  94. 546869300372102187448 / 2 =
  95. 273434650186051093724 / 2 =
  96. 136717325093025546862 / 2 =
  97. 68358662546512773431 * 3 + 1 =
  98. 205075987639538320294 / 2 =
  99. 102537993819769160147 * 3 + 1 =
  100. 307613981459307480442 / 2 =
  101. 153806990729653740221 * 3 + 1 =
  102. 461420972188961220664 / 2 =
  103. 230710486094480610332 / 2 =
  104. 115355243047240305166 / 2 =
  105. 57677621523620152583 <-- !!! CYCLE DETECTED !!!
  106. False
  107. >>>
  108.  
  109. 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.
  110.  
  111. 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