CODING JOY

The stunning potpourri of coding and mundane life

GENERATING PRIME PADOVAN SEQUENCE USING PYTHON



AMRUHA AHMED
9th May,2023.



The Padovan Sequence is a special type of sequence in which the n’th term is determined by the recurrence relation;
P(n)=P(n-2)+P(n-3)
Where P(0),P(1) and P(2) are initialized to 1.
The following figure, in which the length of the current triangle's side is determined by the sum of the lengths of the sides of those triangles that are touching it, can also be used to understand the Padovan Sequence (assuming that this spiral of equilateral triangle is drawn from inside out).

blog1

The task at hand is to generate prime padovan sequence till a number; to display only those terms occurring before the limit which are prime as well as a part of the padovan sequence.


VARIABLES REQUIRED:
ALGORITHM:

The following is the code written in Python to print the Prime Padovan Sequence when the number limit is provided by the user.


PROGRAM:

                
                    p0=1 #first term of the series
                    p1=1 #second term of the series
                    p2=1 #third term of the series
                    pn=p0+p1  #current term of the series
                    n=int(input(("Enter a number:")))  #number till which the series is printed
                    while(pn<=n):
                      ctr=0 #counter to count the number of factors 
                      for i in range(1,pn+1):
                        if(pn%i==0):
                          ctr=ctr+1
                      if(ctr==2):
                        print("{}".format(pn))
                      p0=p1
                      p1=p2
                      p2=pn
                      pn=p0+p1 
                     
             
         
CODE COPIED

DRY RUN:


The dry run is very similar to the one in Padovan Sequence. Additionally, the value of "pn" is checked to see if it is prime or not. For more details about the dry run of Padovan Sequence , Click Here

OUTPUT:

Enter a number:5