HP Forums

Full Version: (12C Platinum) 3n+1 Conjecture
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This program allows to test the 3n + 1 conjecture.

Consider an integer n.
If it's even, divide it by 2 (n÷2)
If it's odd, multiply by 3 and add 1 (3n + 1)

No matter what value of n, the sequence will always reach 1.
The question is: if we start with an arbitrary integer will we always reach 1?
Nobody knows.
--------------------------------------
Procedure:
Positive Integer Number [R/S] display 1
[X<>Y] display Total Iterations
[RCL] 1 display how many time is Odd
[RCL] 2 display how many time is Even
--------------------------------------
Example:

Desire Positive Integer Number is 7

7 [R/S] display 1
[X<>Y] display 16 // Total Iterations
[RCL] 1 display 5 // Odd
[RCL] 2 display 11 // Even
-------------------------------------
Program: FIX 0 (ALG Mode) 38 steps
Code:

STO 0
0
STO 1
STO 2
RCL 0 ÷ 2 = FRAC  
X=0
GTO 022
1
STO+1
RCL 0 x 3 + 1 = 
STO 0
GTO 005
------------------------------
1
STO+2
RCL 0 ÷ 2 = 
STO 0
1
X<>Y
X≤Y 
GTO 034
GTO 005
-----------------------------
RCL 1 + RCL 2 =
RCL 0

***Let's try this on a much faster 12C Platinum Emulator.***

[EEX] 99 [R/S] display 1
[X<>Y] display 567
RCL 1 display 92
RCL 2 display 475

That 92 odds VS 475 even numbers !!!

Gamo
This is the updated version that included the Maximum Value as well.

Procedure: (RPN mode)
Mostly the same as previous post but added the Maximum Value.
The maximum value is the highest point then each steps drop down to 1.

n [R/S] display 1
[X<>Y] display Iterations
[RCL] 1 display Odd
[RCL] 2 display Even
[RCL] 3 display Maximum

------------------------------------
Example: FIX 0

7 [R/S] display 1
[X<>Y] display 16 // Iterations
[RCL] 1 display 5 // Odd
[RCL] 2 display 11 // Even
[RCL] 3 display 52 // Max

-------------------------------------
Program: (RPN mode)
Code:

001 STO 0
002  0
003 STO 1
004 STO 2
005  2
006 STO 3   // Initialize 
------------------
007 RCL 0
008  2
009  ÷
010 FRAC
011 X=0    // Test for Even or Odd 
012 GTO 026  // Even start here
013  1    // Odd start here
014 STO+1
015 RCL 0
016  3
017  x
018  1
019  +
020 STO 0
----------------
021 RCL 3
022 X≤Y
023 X<>Y
024 STO 3   // Store Maximum Value
025 GTO 007  // Loop
----------------
026  1
027 STO+2
028 RCL 0
029  2
030  ÷
031 STO 0
032  1
033 X<>Y
034 X≤Y
035 GTO 037   // End Loop
036 GTO 007   // Loop
037 RCL 1  // Odd
038 RCL 2  // Even
039  +    // Total Iterations
040 RCL 0  // Final result is 1

Gamo
Hello, Gamo !

Nice program.
I do appreciate the subject because I like to program this mathematical guess (known as Czech guess in French) to evaluate and test my new calculators.
I've never thought to introduce the search of the maximum and the odd/even distribution in my program and I think you had a good idea !

I deliver you my current version for HP12C / HP12C+ !

Thanks

-----------------------------------------------------------------------------------------------------------------
(12-27-2018 07:04 AM)Gamo Wrote: [ -> ]This is the updated version that included the Maximum Value as well.

Procedure: (RPN mode)
Mostly the same as previous post but added the Maximum Value.
The maximum value is the highest point then each steps drop down to 1.

n [R/S] display 1
[X<>Y] display Iterations
[RCL] 1 display Odd
[RCL] 2 display Even
[RCL] 3 display Maximum

------------------------------------
Example: FIX 0

7 [R/S] display 1
[X<>Y] display 16 // Iterations
[RCL] 1 display 5 // Odd
[RCL] 2 display 11 // Even
[RCL] 3 display 52 // Max

-------------------------------------
Program: (RPN mode)
Code:

001 STO 0
002  0
003 STO 1
004 STO 2
005  2
006 STO 3   // Initialize 
------------------
007 RCL 0
008  2
009  ÷
010 FRAC
011 X=0    // Test for Even or Odd 
012 GTO 026  // Even start here
013  1    // Odd start here
014 STO+1
015 RCL 0
016  3
017  x
018  1
019  +
020 STO 0
----------------
021 RCL 3
022 X≤Y
023 X<>Y
024 STO 3   // Store Maximum Value
025 GTO 007  // Loop
----------------
026  1
027 STO+2
028 RCL 0
029  2
030  ÷
031 STO 0
032  1
033 X<>Y
034 X≤Y
035 GTO 037   // End Loop
036 GTO 007   // Loop
037 RCL 1  // Odd
038 RCL 2  // Even
039  +    // Total Iterations
040 RCL 0  // Final result is 1

Gamo
Nihotte(lma) Thanks for the review.

Very nice program short and concise.

Gamo
Reference URL's