Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Writing some code to find the first 100 iterations of the 3x+1 problem
Author Message
KissTheCook2004

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.

(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;

scholarlytutor

Posted: 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

Posted: 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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: