Computers and Technology
Computers and Technology, 11.04.2020 02:51, andy6128

The Simplest Impossible Math Problem

In this problem, you are going to program a sequence of steps for a mathematical conjecture whose proof has eluded mathematicians for almost a century.

Here is the procedure:

pick a number X
repeat until X equals 1:
if the number is even, divide it by 2
if the number is odd, multiply it by 3 and add 1
The claim is that this procedure will always converge regardless of the initial value of X.

Your task is to prove this conjecture… just kidding! Your task is to program this procedure using a command line argument as input. For example, if your script is called main. py, you can assume we called your script with python main. py X where X is the input positive integer. Specifically, fill in the code for the converge(n) function which implements this procedure. It received a positive integer n, and returns the number of iterations the procedure took to complete. Also fill out the code under if __name__ == "__main__": to retrieve the first command line argument and print out text to match the following format:

With an input of X we converged to 1 after Y iterations.

where X is the input to the program and Y is the number of iterations it took to converge to 1. You can see most test cases but we've hidden a couple from you.

Given Code:

import sys

# conjecture() take a positive integer n and returns the number of executions of the loop
def conjecture(n):

if __name__ == "__main__":
# retrieve the input, it is passed as the first argument when calling the script
n =
# conjecture takes a positive integer n as input and returns
# the number of loop iterations the loop took to converge
print("With an input of",,"we converged to 1 after",,"iterations.") # fill this in!

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 12:30, gerardoblk5931
An atom's diameter is about 0.1 nanometer (1×10-9m), and a human hair is about 1×10-3m. how many times greater is a human hair than an atom's diameter? sorry pushed wronf button but this is math
Answers: 3
image
Computers and Technology, 23.06.2019 10:00, karissanichole18
Install and use wireshark program ( send back screen shots and other vital information) case project 3-2: decode a tcp segment in a wireshark capture in this chapter, you walked through tcp segment to interpret the data included in its header. in this project, you use wireshark to capture your own http messafes, examine the tcp headers, and practice interpreting the data you'll find there. 1. open wireshark and snap the window to one side of your screen. open a browser and snap that window to the other side of your screen so you can see both windows.
Answers: 2
image
Computers and Technology, 23.06.2019 16:30, mirmir62
Which of the following is not an enhancement to the standard wiki to make it more attractive for corporations? encryptionwork spacespermission toolspredictive text
Answers: 2
image
Computers and Technology, 23.06.2019 18:30, bsept1018
Report all segments of identity by descent longer than 20 polymorphisms between pairs of individuals in the following cohort of 15 individuals across 49 polymorphisms: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 numeric input 2 points possible (graded) you have 2 attempts to complete the assignment below. for example if the sequence is "bcd", which occurs in "abcdef" , the starting point would be 2 (b), and the finishing point would be 4(d). individuals 7,10 between positions
Answers: 1
Do you know the correct answer?
The Simplest Impossible Math Problem

In this problem, you are going to program a sequenc...

Questions in other subjects:

Konu
Mathematics, 29.10.2020 21:10
Konu
Mathematics, 29.10.2020 21:10
Konu
Mathematics, 29.10.2020 21:10
Konu
Mathematics, 29.10.2020 21:10