| Author | Message |
|---|---|
| KissTheCook2004 |
Post Posted: Mon Aug 02, 2021 3:52 pm Post subject: Writing some code to find the first 100 iterations of the 3x+1 problem
|
| I've double checked both my formula and code multiple times, as far as I can see it should work, however my Turing is bugged and I cannot open the syntax documentation.
I have checked my formula by hand up to 15, and it works as intended, however the code makes it to the 2nd or 3rd iteration, goes to zero, and gets stuck. For those unfamiliar, you take a starting number, and if it is even, you divide by 2, if it is odd, you multiply by 3 and add 1. If a number reaches 1, it will go to 4, then 2, then back to 1, and loop from there. Please note in my comments I use [] to represent subscript (delay function is there so I can see what the output is) Turing: /* t[n]=(3t[n-1])mod(t[n-1],2)+(t[n-1]/2)mod(t[n-1]+1,2) t[1]=input seed {t is an element of Z | t>0} */ var tLast : int; for tFirst : 1..100; tLast := tFirst; put tLast; loop; exit when tLast = 1; delay (5000); tLast := (3 * tLast + 1) * tLast mod 2 + (tLast div 2) * (tLast + 1) mod 2; put tLast; end loop; end for; |
|