(34S) Collatz Conjecture - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Software Libraries ( /forum-10.html)+--- Forum: General Software Library ( /forum-13.html)+--- Thread: (34S) Collatz Conjecture ( /thread-1496.html) |

(34S) Collatz Conjecture - Dave Britten - 05-31-2014 08:11 PM
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'` RE: (WP-34S) Collatz Conjecture - Didier Lachieze - 05-31-2014 08:44 PM
The Collatz Conjecture is also called the Syracuse problem. Here is my version for the WP 34S in 19 steps: Code: `001 LBL A` |