Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve in python! A hailstone sequence is an infinite sequence that is generated recursively by the following rule: b 1 = S , b

Please solve in python!
A hailstone sequence is an infinite sequence that is generated recursively by the following rule: b1=S,bn+1={12bnifbniseven3bn+1ifbnisodd
where the positive integer S is the seed value. This sequences name is inspired by the behavior of its values, which typically ascend and descend erratically like hailstones in a strong storm.
(a) Choose any four seed values less than 25 and print the first 30 terms of the corresponding
hailstone sequences. Do you notice any patterns in the behavior of these values as each sequence progresses? Print a statement that precisely describes your observations.
(b) Write a Python function that performs the following tasks:
Accept a seed integer as input.
Print True if the pattern you observed in part (a) appears within the first 300 terms of the corresponding hailstone sequence. If not, print False.
If True was printed, also print the number of terms that had to be checked before the
predicted pattern occurred.
Run your function with the seed integers S=157,1011,3453,5722.
(c) Using plt.plot(), graph the following partial hailstone sequences.
(i) S =103 with n 88.
(ii) S =385 with n 33.
(iii) S =512 with n 10.
(iv) S =1758 with n 149.
Note: You may need to use plt.show() after each plotting command to separate the graphs into different images.
image text in transcribed

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions