Write program in python with a function occupy(n), which shows how birds are going to occupy n nests, assuming that each new bird will choose the nest in the middle of the largest unoccupied run of nests. For example, if there were 10 nests, occupy(10) would print out the following sequence, where underscore indicates an unoccupied nest, and X indicates an occupied nest. The first line of the printout is just 10 underscores showing that all the nests are unoccupied. The second line shows that a bird came to nest in position 5, since that is one the first middle positions of the unoccupied run from 0 to 9. In the third line a bird came to occupy the middle position for the longest open run of nests, from 0 to index 4.
Write program in python with a function occupy(n), which shows how birds are going to occupy n nests, assuming that each new bird will choose the nest in the middle of the largest unoccupied run of nests. For example, if there were 10 nests, occupy(10) would print out the following sequence, where underscore indicates an unoccupied nest, and X indicates an occupied nest. The first line of the printout is just 10 underscores showing that all the nests are unoccupied. The second line shows that a bird came to nest in position 5, since that is one the first middle positions of the unoccupied run from 0 to 9. In the third line a bird came to occupy the middle position for the longest open run of nests, from 0 to index 4.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images