Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python The hailstone sequence is defined as the integer sequence that results from manipulating a positive integer value n as follows: If n is even,

image text in transcribed

Python

The hailstone sequence is defined as the integer sequence that results from manipulating a positive integer value n as follows: If n is even, divide it by 2 (using integer division) Ifn is odd, multiply it by 3 and then add 1 Repeat this process until you reach 1 For example, starting with n = 5, we get the sequence 5, 16, 8, 4,21 If n = 6, we get the sequence 6, 3, 10, 5, 16, 8, 4, 2, 1 If n 7, we get 7, 22. 11, 34, 17, 52. 26, 13. 40. 20. 10. 5, 16, 8, 4.2 1 As far as anyone can tell, this process will eventually reach 1 for any starting value, although mathematicians have been unable to formally prove this property as of yet. For this part of the assignment you will actually write two functions, although only the second one will actually be tested hail.length (n) returns the total number of values in the hailstone sequence generated from the function argument (including the initial value and the final 1). For example, hail.length (5) would return the value 6 siblings (length, maximum), which uses hail.length) internally to find all of the integers from 1 through the maximum (inclusive) that generate a hailstone sequence of the specified length. These values are added to a list which is returned by siblings ). For example, siblings (6,35) would return the list [5, 32]. siblings (10,100) would return [12, 13, 80, 84, 85]. The values in the list need not be sorted, as in these examples Examples: Function Call siblings (1, 968) [1] siblings (15, 853) [11, 68, 69, 70, 75, 384, 416, 424, 426, 452, 453, 454] siblings (20, 107) [9, 56, 58, 60, 61] siblings (13, 825) [17, 96, 104, 106, 113, 640, 672, 680, 682] siblings (8, 700) [3, 20, 21, 128] siblings (15, 181) [11, 68, 69, 70, 75] siblings (10, 748)[12, 13, 80, 84, 85, 512] siblings (6, 205) [5, 32] siblings (9, 113) [6, 40, 42] siblings (7, 152) [10, 64 Return Value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions