Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Writing some code to find the first 100 iterations of the 3x+1 problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
KissTheCook2004




PostPosted: 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;


Sponsor
Sponsor
Sponsor
sponsor
scholarlytutor




PostPosted: Fri Aug 13, 2021 6:16 pm   Post subject: RE:Writing some code to find the first 100 iterations of the 3x+1 problem

I'm not 100% sure what you are trying to accomplish. I can however say your Turing is NOT buggy - you won't be able to see the Turing reference manual if you did not setup Turing correctly.

Feel free to PM me as I can probably fix your problem with Turing, and I may be able to help you with the code as well.
Insectoid




PostPosted: Sat Sep 04, 2021 9:57 am   Post subject: RE:Writing some code to find the first 100 iterations of the 3x+1 problem

Well it's a month later, but if you ever read this I suggest you review your BEDMAS. Div/mod are considered to be division for the purpose of order of operations.
Insectoid




PostPosted: Sat Sep 04, 2021 9:58 am   Post subject: RE:Writing some code to find the first 100 iterations of the 3x+1 problem

Well it's a month later, but if you ever read this I suggest you review your BEDMAS. Div/mod are considered to be division for the purpose of order of operations.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: