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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question

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)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning