ztalloc ecneuqes def ztalloc (shape): The famous Collatz sequence was used in the lectures as an example of a situation that requires the use of a while-loop, since we cannot know beforehand how many steps are needed to get to the goal from the given starting value. The answer was given as the list of integers that the sequence visits before terminating at its goal. However, we can also look at this sequence in a binary fashion depending on whether each value steps up (3x + 1) or down (x/2) from the previous value, denoting these steps with letters 'u' and 'd', respectively. For example, starting from n=12, the sequence [12, 6, 3, 10, 5, 16, 8, 4, 2, 1]would have the step shape 'ddududddd'. This function should, given the step shape as a string that is guaranteed to consist of only letters u and d, determine which starting value for the Collatz sequence produces that shape. However, this function must also recognize that some shape strings are impossible as entailed by the transition rules of Collatz problem, and correctly return None for all such shapes. You should start from the goal state 1, and perform the given transitions in reverse. Make sure that your function does not accept moves that would be illegal in the original forward-going Collatz sequence. shape Expected result . PPPpnpPPPpnpnpnpn, 15 . PPPpnPPpnppnpnpnp, 14 'uduuudddd' None 'd' 'uuududdddduuuuuuudddddd' None 'duuudddddddd' None

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

please help solve the python programming question. Thank you

ztalloc ecneuqes
def ztalloc (shape):
The famous Collatz sequence was used in the lectures as an example of a situation that requires the
use of a while-loop, since we cannot know beforehand how many steps are needed to get to the
goal from the given starting value. The answer was given as the list of integers that the sequence
visits before terminating at its goal. However, we can also look at this sequence in a binary fashion
depending on whether each value steps up (3x + 1) or down (x/2) from the previous value,
denoting these steps with letters 'u' and 'd', respectively. For example, starting from n=12, the
sequence [12, 6, 3, 10, 5, 16, 8, 4, 2, 1] would have the step shape 'ddududddd'.
This function should, given the step shape as a string that is guaranteed to consist of only letters u
and d, determine which starting value for the Collatz sequence produces that shape. However, this
function must also recognize that some shape strings are impossible as entailed by the transition
rules of Collatz problem, and correctly return None for all such shapes. You should start from the
goal state 1, and perform the given transitions in reverse. Make sure that your function does not
accept moves that would be illegal in the original forward-going Collatz sequence.
shape
Expected result
'ududududddddudddd'
15
'dudududdudddudddd'
14
'uduuudddd'
None
'd'
2
'uuududdddduuuuuuudddddd
None
'duuudddddddd'
None
Transcribed Image Text:ztalloc ecneuqes def ztalloc (shape): The famous Collatz sequence was used in the lectures as an example of a situation that requires the use of a while-loop, since we cannot know beforehand how many steps are needed to get to the goal from the given starting value. The answer was given as the list of integers that the sequence visits before terminating at its goal. However, we can also look at this sequence in a binary fashion depending on whether each value steps up (3x + 1) or down (x/2) from the previous value, denoting these steps with letters 'u' and 'd', respectively. For example, starting from n=12, the sequence [12, 6, 3, 10, 5, 16, 8, 4, 2, 1] would have the step shape 'ddududddd'. This function should, given the step shape as a string that is guaranteed to consist of only letters u and d, determine which starting value for the Collatz sequence produces that shape. However, this function must also recognize that some shape strings are impossible as entailed by the transition rules of Collatz problem, and correctly return None for all such shapes. You should start from the goal state 1, and perform the given transitions in reverse. Make sure that your function does not accept moves that would be illegal in the original forward-going Collatz sequence. shape Expected result 'ududududddddudddd' 15 'dudududdudddudddd' 14 'uduuudddd' None 'd' 2 'uuududdddduuuuuuudddddd None 'duuudddddddd' None
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY