HP 12C: Heron’s Formula, Ulam’s Conjecture, and Prime
Factorization
The following programs have been ported to the HP 12C
from various programs presented in the 1980 book, “Programmable Pocket
Calculators” by Henry Mullish and Stephen Kochan. Please see the reference at the end of this
entry.
HP 12C: Heron’s Formula
Heron’s Formula calculates the area of a triangle with
side measurements a, b, and c.
Area = √( s * (sa) *(sb) *(sc)), with s = (a + b +
c)/2
Based on the original program for HP 67 (pg. 170 of
Source)
STEP

CODE

KEY

01

44, 1

STO 1

02

31

R/S

03

44, 2

STO 2

04

31

R/S

05

44, 3

STO 3

06

45, 1

RCL 1

07

40

+

08

45, 2

RCL 2

09

40

+

10

2

2

11

10

÷

12

44, 4

STO 4

13

45, 1

RCL 1

14

30



15

45, 4

RCL 4

16

20

*

17

45, 4

RCL 4

18

45, 2

RCL 2

19

30



20

20

*

21

45, 4

RCL 4

22

45, 3

RCL 3

23

30



24

20

*

25

43, 21

√

26

43, 33, 00

GTO 00

Instructions:
Input a, press [R/S], input b, press [R/S], input c,
[R/S]. The area will be calculated.
Test 1: a = 4.00,
b = 5.00, c = 3.00 Result: 6.00
Test 2: a = 10.00,
b= 15.00, c = 20.00 Result: 72.62
Test 3: a = 7.00,
b = 8.00, c = 9.00 Result: 26.83
HP 12C: Ulam’s Conjecture
This program counts the many steps needed to reduce a positive
integer to 1, by the following rules:
If the integer is even, divide by 2.
If the integer is odd, multiply it by 3 and add 1.
If the next integer is 1, stop.
Based on the original program for HP 33E (pg. 239 of
Source)
STEP

CODE

KEY

01

42, 0

FIX 0 ( [ f ],
0)

02

44, 1

STO 1

03

0

0

04

44, 0

STO 0

05

1

1

06

45, 1

RCL 1

07

30



08

43, 35

x=0

09

43, 33, 28

GTO 28

10

45, 1

RCL 1

11

2

2

12

10

÷

13

43, 24

FRAC

14

43, 25

x=0

15

43, 33, 32

GTO 22

16

45, 1

RCL 1

17

3

3

18

20

*

19

1

1

20

40

+

21

43, 33, 23

GTO 23

22

43, 36

LSTx

23

43, 31

PSE

24

44, 1

STO 1

25

1

1

26

44, 40, 0

STO+ 0

27

43, 33, 05

GTO 05

28

45, 0

RCL 0

29

42, 2

FIX 2 ( [ f ],
2)

30

43, 33, 00

GTO 00

Instructions:
Enter the integer, press [R/S]. The number of steps is calculated.
Test 1: 5 takes 5
steps to get to 1 through Ulam’s Conjecture.
Test 2: 21 takes 7
steps to get to 1 through Ulam’s Conjecture.
Test 3: 39 takes 34 steps to get to 1 through Ulam’s
Conjecture.
HP 12C Prime
Factorization
This is the prime factorization of a prime integer. The program ends when the original integer is
returned, and FIX 2 mode is set. Another
change I made was instead of the pause command in the original program, I made
it a run/stop command so that you write down the prime factors at your leisure.
Based on the original program for HP 25/25C (pg. 77 of
Source)
STEP

CODE

KEY

01

42, 0

FIX 0 ( [ f ], 0 )

02

44, 2

STO 2

03

44, 0

STO 0

04

2

2

05

44, 1

STO 1

06

45, 0

RCL 0

07

45 ,1

RCL 1

08

10

÷

09

36

ENTER

10

43, 24

FRAC

11

43, 35

x=0

12

43, 33, 16

GTO 16

13

1

1

14

44, 40, 1

STO+ 1

15

43, 33, 06

GTO 06

16

45, 1

RCL 1

17

31

R/S

18

33

Rdown, R↓

19

33

Rdown, R↓

20

44, 0

STO 0

21

1

1

22

30



23

43, 35

x=0

24

43, 33, 26

GTO 26

25

43, 33, 06

GTO 06

26

45, 2

RCL 2

27

42, 2

FIX 2 ( [ f ],
2)

28

43, 33, 00

GTO 00

Instructions:
Enter the integer, press [R/S].
Each factor is displayed, while in FIX 0 mode. Press [R/S] for each factor. If the number is prime, then only the integer
is shown.
Test 1: 100.
Results: 2, [R/S], 2, [R/S], 5, [R/S], 5, [R/S], 100.00
100 = 2^2 * 5^2
Test 2: 255. Results:
3, [R/S], 5, [R/S], 17, [R/S], 255.00
255 = 3 * 5 * 17
Test 3: 11. Results: 11 [R/S], 11.00
11 is prime
Source:
Mullins, Henry and Stephen Kochan. Programmable
Pocket Calculators Hayden Book
Company. Rochelle Park, NJ 1980.
Eddie
This blog is property of Edward Shore, 2016.