The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
(HP-65) Collatz Conjecture
01-08-2020, 07:03 PM
Post: #1
(HP-65) Collatz Conjecture
Yeah, it's been done a million times before, but just for posterity...

Basic premise: The Collatz Conjecture states that you can start from any positive integer; if it's even, divide it by 2, and if it's odd, multiply by 3 and add 1. Continue this sequence, and you will always eventually reach 1.

Usage

Enter a positive integer in X, press A, and the program will tell you the number of steps required to reach 1 starting from your number. If you set flag 1 before running the program, it will stop to display each number in the sequence. Press R/S to calculate the next number.

Code:
LBL     23
A       11
0       00
STO 8   33 08
g RDown 35 08
LBL     23
1       01
1       01
g x=y   35 23
GTO     22
9       09
g RDown 35 08
ENTER   41
ENTER   41
2       02
/       81
ENTER   41
f       31
INT     83
g x=y   35 23
GTO     22
2       02
g RDown 35 08
g RDown 35 08
3       03
*       71
1       01
+       61
LBL     23
2       02
g       35
DSZ     83
f       31
TF 1    61
R/S     84
NOP     35 01
GTO     22
1       01
LBL     23
9       09
RCL 8   34 08
CHS     42
RTN     24

If you don't need the ability to set flag 1 to view the sequence, you can omit these four steps shortly after LBL 2 for a roughly 9% speed up:

f, TF 1, R/S, NOP
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(HP-65) Collatz Conjecture - Dave Britten - 01-08-2020 07:03 PM



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