Post Reply 
(34S) Collatz Conjecture
05-31-2014, 08:11 PM (This post was last modified: 06-15-2017 01:20 PM by Gene.)
Post: #1
(34S) Collatz Conjecture
Briefly, the Collatz Conjecture states that you can start with any positive integer, and by repeating these two transformations, eventually arrive at 1:

1. If the number is even, divide it by 2.
2. If the number is odd, multiply it by 3 and add 1.

Here's a simple program to evaluate such sequences, and report the number of transformations that were needed to reach 1, as well as the max value that was obtained along the way. Optionally, you can set flag 1 before execution to view the current value being updated in real-time (this slows the program down considerably, though).

Input:
X: Starting Value

Output:
Y: Maximum Value
X: Number of Transformations

Example:
27 XEQ'CTZ'

In less than one second, you should see 111, the total number of transformations. Press x><y to see the max value, 9,232.

Code:
LBL 'CTZ'
LocR 002
STO .01
0
STO .00
RDown
LBL 00
x=1?
GTO 09
FS? 01
PSE 00
INC .00
EVEN?
GTO 02
3
*
1
+
x>? .01
STO .01
GTO 00
LBL 02
2
/
GTO 00
LBL 09
RCL .01
RCL .00
RTN
END
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(34S) Collatz Conjecture - Dave Britten - 05-31-2014 08:11 PM



User(s) browsing this thread: 1 Guest(s)