Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Python. Question 1 (collatz.conjecture.py): The Collatz Conjecture or 3r +1 problem can be summarized as follows Take any positive integer n. If n is

Use Python.

image text in transcribedimage text in transcribed

Question 1 (collatz.conjecture.py): The Collatz Conjecture or 3r +1 problem can be summarized as follows Take any positive integer n. If n is even, divide n by 2 to get n/2. If n is odd, multiply n by 3 and add 1 to get 3n +1. Repeat the process indefinitely. The conjecture states that no matter which number you start with, you will always reach 1 eventually. Given a number n return the number of steps required to reach 1 For example, starting with n = 12, the steps would be as follows: 1. 12 2. 6 3. 3 4. 10 5. 5 6. 16 7. 8 8. 4 9. 2 10. 1 Write a function called 'collatz.conjecture' that accepts a numerical argument. The function should return number of iterations required for transforming the input to using the given operations. For example, calling collatz.conjecture (12) should return 9. Notes: The Collatz Conjecture is only concerned with strictly positive integers, so your solution should raise a ValueError if given 0 or a negative integer. SO

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions