Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use python please! The Collatz problem our code for this problem should go in a file called collatz.py he Collatz function works like this: given

Use python please!
image text in transcribed
The Collatz problem our code for this problem should go in a file called collatz.py he Collatz function works like this: given a positive integer n greater than 1 as input, if n is even, divide it by 2. If n is odd, multiply it by 3 and then dd 1. Mathematicians have conjectured that if we start with any positive integer greater than 1 and repeatedly apply the Collatz function, we'll eventually get the number 1. or example, consider starting with 5. Since it's odd, the Collatz function returns 16. Now, applying the Collatz function to 16, we get 8. Applying it to 8 we get 4. Then we get 2 and then we get 1 The Collatz Conjecture namely that repeatedly "Collatz-ing" any positive number greater than 1 will eventually turn that number to 1 - is still an open problem in mathematics. Your task is to write some functions that will help test (but, alas, not prove) the conjecture. First, write a function called collatz(n) that takes a positive integer and returns the result of applying the Collatz function (just once) to it. This will be e very short function. Next, write a function called cC(n) (which stands for "Count Collatz") that takes a positive integer n as input and returns the number of times that the Collatz function must be applied before the result is 1. If n is equal to 1, then cC should return 0. If n is equal to 5, then cc should return 5 since, as we saw above, the sequence is 5, 16, 8, 4, 2, 1 and there are five applications of Collatz to get from 5 to 1. You'll need to use a while loop herel Finally, try out your cc function on a variety of different values of n to see if you believe that the Collatz Conjecture is true

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

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago