Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Collatz conjecture Consider the following procedure: 1. Start with an integer x. 2. If x is even, then divide it by 2; if it's odd,

Collatz conjecture

Consider the following procedure:

1. Start with an integer x.

2. If x is even, then divide it by 2; if it's odd, instead multiply it by 3 and add 1.

3. Repeat this process until x = 1.

For example, starting with x=15 would give the sequence of numbers 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1. Write a program that has the user enter a value for x and then displays the resulting sequence. To check whether a number is even you should use the % operator: if x is even, then x % 2 == 0 and if it's odd x % 2 == 1.

Extra note from my professor: (Background: the Collatz conjecture is that regardless of what number you start with, you will eventually reach 1 through this procedure. Although it was formulated about 80 years ago, nobody has yet managed to prove or disprove it it has been checked by computer up to x=6,000,000,000,000,000,000 and so far every one of them has had this behavior, but it is still not known whether it's true for all integers. If you happen to find an x that doesn't go to 1, you could win some notoriety!)

This is a beginner course, so the program can be kept fairly simple. I have no experience with programming, so most stuff is all new to me. The main topics of our lectures/chapter this week were Indefinite (while) loops, File loops, Nested loops, Boolean logic, Nesting if statements and loops.

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

Students also viewed these Databases questions

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago