#! /usr/bin/env python3 # def football_scores_test ( ): #*****************************************************************************80 # ## football_scores_test() tests football_scores(). # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 September 2022 # # Author: # # John Burkardt # import platform timestamp ( ) print ( '' ) print ( 'football_scores_test()' ) print ( ' Python version: ' + platform.python_version ( ) ) print ( ' football_scores() computes the number of ways' ) print ( ' of achieving a particular score in football.' ) print ( '' ) print ( ' We assume scoring options are:' ) print ( '' ) print ( ' +1 for a one point safety (returned conversion' ) print ( ' after the other team scores a touchdown.' ) print ( ' +2 for a safety' ) print ( ' +3 for a field goal' ) print ( ' +6 for a touchdown with no followup' ) print ( ' +7 for a touchdown with a point bonus' ) print ( ' +8 for a touchdown with two point conversion' ) print ( '' ) print ( ' Score Ways' ) print ( '' ) # # You get a score of N points by # N-1 + a 1 point safety, # N-2 + a safety, or # N-3 + a field goal, or # N-6 + a touchdown with no followup # N-7 + a touchdown with a point bonus, or # N-8 + a touchdown with two point conversion. # n = 50 s = football_scores ( n ) for i in range ( 0, n + 1 ): print ( i, s[i] ) print ( '' ) print ( 'football_scores_test()' ) print ( ' Normal end of execution.' ) print ( '' ) timestamp ( ) return def football_scores ( n ): #*****************************************************************************80 # ## football_scores() counts the ways of getting any football score from 0 to 100. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 September 2022 # # Author: # # John Burkardt # # Input: # # integer n: the highest score to be considered. # # Output: # # integer football_scores[n+1]: the number of ways of achieving each score # from 0 to n. # import numpy as np s = np.zeros ( n + 1, dtype = int ) for i in range ( 0, n + 1 ): if ( i == 0 ): s[i] = 1 if ( 1 <= i ): s[i] = s[i] + s[i-1] if ( 2 <= i ): s[i] = s[i] + s[i-2] if ( 3 <= i ): s[i] = s[i] + s[i-3] if ( 6 <= i ): s[i] = s[i] + s[i-6] if ( 7 <= i ): s[i] = s[i] + s[i-7] if ( 8 <= i ): s[i] = s[i] + s[i-8] return s def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 August 2019 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return if ( __name__ == '__main__' ): timestamp ( ) football_scores_test ( ) timestamp ( )