See attached
Computer Science I CSCI-141 Integer Sequences Homework 4 09/05/2021 1 Problem >>> p r i n t s e q u e n c e i t e r ( 3 , 20) 3 11 27 59 123 251 507 1019 2043 4091 8187 16379 32763 65531 131067 262139 524283 1048571 2097147 4194299 8388603 An integer sequence is a sometimes infinite chain of integer values. In some cases the later values in the sequence are computed from earlier values in the sequence. An example of such a sequence is the Fibonacci sequence. Starting from 0 and 1, the sequence’s next value is the sum of the previous two numbers before it. Thus we have 0, 1, 1, 2, 3, 5, 8, 13, 21, and on to infinity. This assignment concerns itself with “double plus 5” sequences. These sequences start with any non-negative integer, 0, 1, and so on. If the start value is v0, the number after the start value has a value of (v0 × 2 + 5), and the number after that continues the pattern up to some number of steps. For example, if the start value is 1, the “double plus 5” sequence is: 1 7 19 43 91 ... Each step is a transition from one value to the next, and the number of elements in a sequence is one more than the step count because the start value marks the beginning, before any transitions. 1.1 Functions to Write 1. print_sequence_rec( start, count) print a sequence of count steps recursively. 2. print_sequence_iter( start, count) print a sequence of count steps iteratively. 3. find_start_forward( goal, count) return a sequence start value. 1.2 Function Requirements The first two functions print values and are not fruitful. In contrast, the third functions returns its results rather than printing them; it is thus a fruitful function. • print_sequence_rec( start, count) recursively generates and prints count steps of the sequence from the start value. The values of the sequence print on a sin- gle line separated by a single space. The actual output is count + 1 numbers long because it prints the start. Examples: 1 >>> print_sequence_rec( 1, 2) 1 7 19 >>> print_sequence_rec( 2, 5) 2 9 23 51 107 219 • print_sequence_iter( start, count) iteratively generates and prints count steps of the double plus 5 sequence from the start value. The values of the sequence print on a single line separated by a space. The actual output is count+ 1 numbers long because it prints the start. Examples: >>> print_sequence_iter( 1, 2) 1 7 19 >>> print_sequence_iter( 2, 5) 2 9 23 51 107 219 >>> print_sequence_iter( 121, 3) 121 247 499 1003 • find_start_forward( goal, count) iteratively searches forward from an initial start value of 0, computes the sequence until the last value is greater than or equal to the goal, and returns the start value of the sequence. For example, find_start_forward( 7, 3) asks the question: “What start value produces a double plus five sequence that is 3 steps long ending in 7 or greater?” The pre-conditions are that goal >= 0 and count >= 0. If the double plus 5 sequence starting at 0 cannot reach the goal in count steps, then try starting at 1. If that fails, then try starting at 2, and so on. Continue this process until you find a start value N that does reach or exceed goal in count steps, and return that start value. Examples: >>> find_start_forward( 100, 4) 2 >>> find_start_forward( 100, 3) 9 Remember: The sequence 2, 9, 23, 51, 107 is four steps; the count measures the number of changes, not the number of values in the sequence. 1.3 Examples Your functions should produce results similar to these examples. >>> from doub l e add5 so l import ∗ >>> p r i n t s e qu en c e r e c ( 0 , 0) 0 >>> p r i n t s e qu en c e r e c ( 1 , 2) 1 7 19 >>> p r i n t s e q u e n c e i t e r ( 2 , 5) 2 2 9 23 51 107 219 >>> p r i n t s e qu en c e r e c ( 1 , 0) 1 >>> p r i n t s e q u e n c e i t e r ( 1 , 1) 1 7 >>> f i n d s t a r t f o rwa r d ( 7 , 2) # 2 s t e p s from what s t a r t i s >= 7? 0 >>> f i n d s t a r t f o rwa r d ( 7 , 3) # 0 5 15 i s 2 s t e p s and pas t 7 0 >>> f i n d s t a r t f o rwa r d ( 8 , 3) 0 >>> f i n d s t a r t f o rwa r d ( 9 , 2) 0 >>> f i n d s t a r t f o rwa r d ( 100 , 1) # 48 ∗ 2 + 5 i s >= 100 48 >>> f i n d s t a r t f o rwa r d ( 100 , 3) 9 >>> p r i n t s e q u e n c e i t e r ( 9 , 3) 9 23 51 107 >>> f i n d s t a r t f o rwa r d ( 1000 , 3) 121 >>> p r i n t s e q u e n c e i t e r ( 121 , 3) 121 247 499 1003 >>> p r i n t s e q u e n c e i t e r ( 3 , 19) 3 11 27 59 123 251 507 1019 2043 4091 8187 16379 32763 65531 131067 262139 524283 1048571 2097147 4194299 >>> # and here i s an odd case : count o f 0 i s an i n s t an t goa l >>> value = f i n d s t a r t f o rwa r d ( 100 , 0) >>> print ( va lue ) 100 2 Testing You should write test functions that run your fruitful functions and check their return values for correctness. You may use the examples as a source of some answers, but you should also run some of your own, manual computations and use their results as the expected values to be returned by the fruitful functions. When the program runs, it should execute your tests. 3 Grading • 25%: print_sequence_rec( start, count) 3 • 25%: print_sequence_iter( start, count) • 25%: find_start_forward( goal, count) • 15%: Testing that the functions work over a reasonable set of test cases. • 5%: Each function has a docstring containing a sentence describing its purpose. Documentation helps others understand how they may reuse the function. A style example is provided under the Course Resources webpage and linked here: http://www.cs.rit.edu/~csci141/Docs/style-example-py.txt • 5% The program is in correct, standard style, and the file docstring contains your full name and email author entry. 4 Submission Zip the file called double_add5.py into a file hw04.zip and submit the zip file to the MyCourses dropbox for this assignment. You must use zip format and no other. You will lose points for failure to submit properly. 4 http://www.cs.rit.edu/~csci141/Docs/style-example-py.txt Problem Functions to Write Function Requirements Examples Testing Grading Submission