Post Reply 
(30b) Perrin Sequence & a Quick Prime Test
11-20-2014, 04:44 PM (This post was last modified: 06-15-2017 01:24 PM by Gene.)
Post: #1
(30b) Perrin Sequence & a Quick Prime Test
Perrin sequence for integer input > 0

0 P0
1 Lbl 01
2 STO 2
3 3
4 STO 1
5 1
6 +/-
7 =
8 1
9 =
10 1
11 +/-
12 =
13 Lbl 00
14 RCL 1
15 R↓
16 +
17 STO 1
18 R↓
19 Swap
20 1
21 STO- 2
22 RCL* 2
23 GT 00
24 RCL 1
25 RTN

The Perrin sequence beginning at index 1 is 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, 22, 29, 39, 51, 68, 90, 119, 158, 209, 277, 367, 486 …

The programme returns exact values for indices 1 to 98, thereafter approximate.

A pleasant attribute of the series is that if the index divides the indexed value with non-zero remainder the index is not prime.
Accordingly, a quick prime test follows:

0 P1
1 STO 3
2 Call01
3 RCL/ 3
4 Math
5 Up
6 Input
7 0
8 ?=
9 RTN

All primes in the range 2 to 98 are correctly identified with a 1 returned, as are all non-primes shown by a 0.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)