#! /usr/bin/env python # def padovan ( n ): #*****************************************************************************80 # ## PADOVAN returns the first N values of the Padovan sequence. # # Discussion: # # The Padovan sequence has the initial values: # # P(0) = 1 # P(1) = 1 # P(2) = 1 # # and subsequent entries are generated by the recurrence # # P(I+1) = P(I-1) + P(I-2) # # Example: # # 0 1 # 1 1 # 2 1 # 3 2 # 4 2 # 5 3 # 6 4 # 7 5 # 8 7 # 9 9 # 10 12 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 May 2015 # # Author: # # John Burkardt # # Reference: # # Ian Stewart, # "A Neglected Number", # Scientific American, Volume 274, pages 102-102, June 1996. # # Ian Stewart, # Math Hysteria, # Oxford, 2004. # # Parameters: # # Input, integer N, the number of terms. # # Output, integer P(N), terms 0 though N-1 of the Perrin sequence. # import numpy as np p = np.zeros ( n ) if ( 1 <= n ): p[0] = 1 if ( 2 <= n ): p[1] = 1 if ( 3 <= n ): p[2] = 1 for i in range ( 3, n ): p[i] = p[i-2] + p[i-3] return p def padovan_test ( ): #*****************************************************************************80 # ## PADOVAN_TEST tests PADOVAN. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 May 2015 # # Author: # # John Burkardt # import platform from i4vec_print import i4vec_print n = 10 print ( '' ) print ( 'PADOVAN_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' PADOVAN computes the Padovan numbers.' ) p = padovan ( n ); i4vec_print ( n, p, ' Initial Padovan sequence:' ) # # Terminate. # print ( '' ) print ( 'PADOVAN_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) padovan_test ( ) timestamp ( )