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 23:30, Molly05
In my email i got a message it says a quick message and in message details on who its from its says nicole and under nicole is 50e0bf08e5b671@ualwgypg91wa5wl. uzo9kbud3qjwddygd5.vng -
Answers: 1
image
Computers and Technology, 23.06.2019 02:30, bre563
Research data that is presented using descriptive language is said to be
Answers: 2
image
Computers and Technology, 23.06.2019 14:30, Vanesssajohn2962
Norder to receive financial aid at his vocational school, mario must fill out the fafsa. the fafsa is a form that must be completed to determine . in order to complete a fafsa, you must submit . the fafsa can students obtain
Answers: 2
image
Computers and Technology, 23.06.2019 21:50, Trinhphuongtran
Description: write function lastfirst() that takes one argument—a list of strings of the format "lastname, firstname" —and returns a list consisting of two lists: (a) a list of all the last names (b) a list of all the first names
Answers: 2
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: