01-08-2020, 07:03 PM
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.
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
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