factors and primes for 29c
#1

I would humbly like to submit my program (written for the HP29C) to find the prime factors of a given integer, or find all primes between 2 given integers. This program could be adapted to any machine with >= 98 program lines, conditional branching, and at least 6 storage registers. Note that since the 29C doesn't have flags, I have used register 0 as a pseudo flag.

Instructions:
To find prime factors of an integer...put integer in x register and GSB 9. Factors are displayed successively. R/S to see the next factor. 1 is always the final factor displayed. If given integer is prime, factors displayed will be it and 1.

To find primes between two integers, put lower integer into register 6, and upper integer into register 9, and GSB 8.
primes will display from lowest to highest. R/S to view next prime. Display will flash one zero, then 10 zeros, then 3 zeros (fix 2) when finished.
Best regards, Hal

step#           mnewmonic  

1 lbl 9

2 0 set flag register to 0 for prime

3 sto 0 factors routine

4 x<>y

5 lbl 7

6 sto 04

7 sqrt

8 sto 05 set bail out point for finding factors

9 2

10 sto 1

11 gsb 1

12 3 manually check 2,3,5,7 for divisibility

13 sto 1

14 gsb 1

15 5

16 sto 1

17 gsb 1

18 7

19 sto 01

20 gsb 1

21 lbl 3

22 4 increment trial divisor by sequence

23 sto + 1 such that multiples of 2,3 and 5

24 gsb 1 are skipped

25 2

26 sto + 1

27 gsb 1

28 4

29 sto + 1

30 gsb 1

31 2

32 sto + 1

33 gsb 1

34 4

35 sto + 1

36 gsb 1

37 6

38 sto + 1

39 gsb 1

40 2

41 sto + 1

42 gsb 1

43 6

44 sto + 1

45 gsb 1

46 gto 3

47 lbl 1

48 rcl 5

49 rcl 1

50 x>y?

51 gto 5

52 rcl 04

53 x<>y

54 /

55 enter

56 frc

57 x=0?

58 gto 4

59 rtn

60 lbl 4

61 rcl 0

62 x<>0?

63 gto 2

64 rcl 1

65 r/s

66 roll dn

67 roll dn

68 roll dn

69 gto 7

70 lbl 5

71 rcl 4

72 r/s

73 rcl 0

74 x<>0?

75 gto 2

76 1

77 r/s

78 rtn

79 lbl 8

80 9 set flag register to non-zero for

81 sto 0 primes between integers routine

82 rcl 6

83 gto 7

84 lbl 2

85 1

86 sto + 6

87 rcl 9

88 rcl 6

89 x>y?

90 gto 6

91 gto 7

92 lbl 6

93 0

94 pause

95 fix 9

96 pause

97 fix 2

98 r/s

#2

Hi,

Peter Henrici in his book "Computational Analysis with the HP-25 Pocket Calculator" has a prime program for the 25 using all 49 lines, its four storage registers, and of course no flags.

tm

#3

I'll have to check that book out...Henrici must be a master of brevity when programming. There is a prime factors / prime numbers program for the hp67 in the software section of the this website that's 223 lines long (it has a few more bells and whistles for printing options, and error detection, etc).
Best regards, Hal



Possibly Related Threads…
Thread Author Replies Views Last Post
  [WP 34s] Pressure Conversion Factors Timothy Roche 8 3,083 11-04-2013, 07:17 PM
Last Post: Dave Shaffer (Arizona)
  HP Prime: Conversion factors Paul Townsend (UK) 19 4,869 08-27-2013, 09:19 AM
Last Post: Nigel J Dowrick
  HP-29c keyboard dead 2nd row problem Xavier A. (Brazil) 6 2,202 07-17-2012, 07:09 AM
Last Post: Xavier A. (Brazil)
  HP-29C Counterparts Matt Agajanian 2 1,228 05-12-2012, 06:44 PM
Last Post: Matt Agajanian
  My 29C's even more bizarre behaviour Matt Agajanian 5 1,875 04-25-2012, 05:46 PM
Last Post: Matt Agajanian
  29C/25C question. Matt Agajanian 7 2,234 04-03-2012, 12:03 AM
Last Post: Matt Agajanian
  My very schizophrenic 29C Matt Agajanian 9 2,755 04-02-2012, 05:12 PM
Last Post: Matt Agajanian
  Help!! My 29C may need a doctor. Matt Agajanian 5 1,934 03-31-2012, 04:23 AM
Last Post: Ignazio Cara (Italy)
  Legible version of 29C Curve Fitting program Matt Agajanian 6 2,067 03-21-2012, 07:46 PM
Last Post: Matt Agajanian
  Sleek approach to Register Exchange on HP-29C Matt Agajanian 8 2,610 03-16-2012, 01:04 PM
Last Post: Marcus von Cube, Germany

Forum Jump: