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
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...
Related questions
Question
100%
please help solve the python
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0f4c3b8d-420b-4827-8129-a9e5c9a665e1%2F4020d77d-1d82-4d99-8e57-8dbce2a32587%2Flq4jvp8_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY