HP Forums
HP Prime Program: ULAM - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: HP Prime Program: ULAM (/thread-252010.html)



HP Prime Program: ULAM - Eddie W. Shore - 10-02-2013

ULAM - Using Ulam's Conjecture to determine the number of steps it takes to reduce an integer N to 1 using the following rules:

If N is odd: N = 3√óN+1
If N is even: N=N/2

9/24/2013

Program:

EXPORT ULAM(N)
BEGIN
LOCAL C;
PRINT();
REPEAT
IF FP(N/2)==0 THEN
N:=N/2;
ELSE
N:=3*N+1;
END;
C:=C+1;
PRINT(N);
UNTIL N==1;
RETURN C;
END;

Examples:
ULAM(69): 208, 104, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 (14 steps)

ULAM(84): 42, 21, 64, 32, 16, 8, 4, 2, 1 (9 steps)