Reference no: EM133306430
ASSESSMENT DETAILS
Introduction.
Task 1
In this assignment you are required to develop software (a set of functions) that can be used to investigate/research the unsolved mathematical problem called Although the problem is considered to be very difficult, its formulation can be understood by a school student:
Collatz Conjecture: Consider the following operation on an arbitrary positive inteux., n, which we denote f(n):
- If the number n is even, the f(n) = n/2.
- If the number n is odd, f(n) 3*n + 1.
Now form a sequence (a Collatz sequence) by performing this operation repeatedly, beginning with a positive integer, n, and taking the result at each step as the input at the next. You stop once you reach 1.
For example, if n = 3, then the sequence will be:
[3, 10, 5, 16, 8, 4, 2, 1]
Or for n = 7 the sequence is:
(7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1) You can see that in both examples we eventually reach 1.
The Collets Conjecture claims that this is always true, i.v., the process will eventually reach the number 1, regardless ot which positive integer n is chosen initially.
Task 2. Function maxLengths(m).
In this task you are required to write a Python function, maxLength, that returns two integers:
'First returned value: for each integer k, 1≤ k ≤ m, the length of Collatz sequence for each k is computed and the largest of these numbers is returned.
'Second returned value is the integer k, 1 ≤ k ≤ m, whose Collatz sequence has largest length. In case there several such numbers, return the first one (the smallest).
For example, maxLength(10) returns numbers 20 and 9
Which means that among the numbers 1, 2, 3,..., 10, nine has the longest Collatz sequence, and its length is equal to 20.
In your program you may define other (auxiliary) functions with arbitrary names, however, the solution function of this task should be named maxLength(m).
Task 3. Function maxValue(m).
In this task you are required to write a Python function, maxValue, that returns two integers:
'First returned value: for each integer k, 1 S k S m, the maximal integer in the Collatz sequence for k is computed and the largest of these numbers is returned.
'Second returned value is the integer cma4 1 S k S m, whose Collatz sequence Page
;NM the largest maximal member. In 1of6
case there are several such numbers,
return the first one (the smallest).
For example, maxValue(10)returns the numbers
52 and 7
Which means that among the numbers 1, 2, 3,..., 10, seven has the largest maximal number in its Collatz sequence, and that number is equal to 52.
In your program you may define other (auxiliary) functions with arbitrary names, however, the solution function of this task should be named maxValue(m).
Task 4. Function main().
In this task you are required to write a function main() where you test your functions. The output should be similar to the following:
RESTART: Ci/MyPiage/2021/Sesester_2/1TECH1400/A_I/al_collatz.py -------. Enter a positive Integer:
100000
For nunhers <- 100000:
77031 has the longest Collatz sequence. The length is 351.
77671 has the largest number In its ColLatz sequence. The number is 1570824736.
>>>