Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write Python code which computes the Hailstone path length of a positive integer. The Hailstone function is defined as: n/2, n is even 3n

image text in transcribed

1. Write Python code which computes the Hailstone path length of a positive integer. The Hailstone function is defined as: n/2, n is even 3n +1, n is odd h(n) The Hailstone path for an integer n is the sequence of numbers generated by the Hailstone function, beginning at n and ending at 1. The Hailstone path length is the number of integers that appear on the Hailstone path, which is 1 plus the number of applications of the Hailstone function required to reach h (n) = 1, For example, the Hailstone path for 12 is 12 6 3 10516 8- 42 1 Thus, the path length is 10. The function was applied 9 times. It is conjectured that all positive integers eventually reach 1 after repeated application of the Hailstone function. Although the conjecture is believed to be true, it has not yet been proven. Hint 1: use a while loop Hint 2: Use integer division://the double division slash Hint 2: The input function returns a string-you need to convert it to an integer using the int function- ike this: n-input'Enter a value for n ') Your output should look like this (for an input of 12): Enter a value for n 12 12 6 3 10 5 16 8 4 21 The path length is 10 steps Challenge: along with the path length, also find the largest number on the path

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_2

Step: 3

blur-text-image_3

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

How is Karen Slagles argument an example of confirmation bias?

Answered: 1 week ago