PYTHON QUESTION : The Syracuse sequence of an integer N is the sequence of integers starting with the term N, where each following term is half of the preceding term if it is even, and one plus three times the preceding term if it is odd. The sequence ends when it reaches the integer 1. The maximum of the Syracuse sequence of an integer N is the highest number reached by this sequence. This maximum can sometimes be very high compared to the starting integer N. What is the maximum of the Syracuse sequence of 3428767? To answer this question it is useful to modify the code given in demonstration which calculates the Syracuse sequence. The code given in the demo : n = 27 print(n) while n != 1: if n%2 == 0: n = n // 2 # where n //= 2 or n >>= 1 else: n = 1 + 3*n print(n
PYTHON QUESTION :
The Syracuse sequence of an integer N is the sequence of integers starting with the term N, where each following term is half of the preceding term if it is even, and one plus three times the preceding term if it is odd. The sequence ends when it reaches the integer 1.
The maximum of the Syracuse sequence of an integer N is the highest number reached by this sequence. This maximum can sometimes be very high compared to the starting integer N.
What is the maximum of the Syracuse sequence of 3428767?
To answer this question it is useful to modify the code given in demonstration which calculates the Syracuse sequence.
The code given in the demo :
n = 27
print(n)
while n != 1:
if n%2 == 0:
n = n // 2 # where n //= 2 or n >>= 1
else: n = 1 + 3*n
print(n)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images