Question: python 3.6 def n_gens(grid, n=20): Given a Grid and a positive integer of how many generations to store, utilize your next_gen function to create a
python 3.6
def n_gens(grid, n=20):
Given a Grid and a positive integer of how many generations to store, utilize your next_gen function to create a list with
n generations in it, where the given grid is included as the first generation.
o Assume: grid is a Grid; n is a positive integer that may default to 2
0 when not given.
oHints: Use your next_gen definition!
you are returning a list of Grid valuesit is a list that is 3 levels deep!
oThe examples would get pretty largern indicates the same numbered generations from the page of r_pentomino steps;
gridA,gridB, andgridC are also defined above (blinker and boat).
o n_gens(r_pentomino,3)[r0, r1, r2]# see the last page
o n_gens(gridA,5)[gridA, gridB, gridA, gridB, gridA]
o n_gens(gridB,3)[gridB, gridA, gridB]
o n_gens(gridC,4)[gridC, gridC, gridC,gridC]
on_gens([[False]])[[[False]], [[False]], [[False]], [[False]], [[False]], [[False]],[[False]], [[False]], [[False]], [[False]], [[False]], [[False]],
[[False]], [[False]], [[False]], [[False]], [[False]], [[False]],[[False]], [[False]]]
#20 iterations provided by default
def is_still_life(grid, limit=100):
Given a single Grid, determine if its sequence of generations
becomes a "still life", where after some point, each generation matches the previous generation. Note that the chosen cut-off number of generations can change the answer (if a Grid takes 30 generations to settle into a still life, but we only look at 10 generations, we won't realize it, and report False).
o Assume s: grid is a Grid, and limit is a positive integer that may default to 100.
o Hint : try comparing two different (consecutive) Grid values with the==perator.
oExamples use names of provided GridStrings.
o is_still_life(build_grid(boat),5)True
o is_still_life(build_grid(boat),1)False#one grid:can't seestill- life
o is_still_life(build_grid(blinkerA),10)False# period is 2; this isn't still.
o is_still_life(build_grid(r_pentomino),50)False
o is_still_life(build_grid(r_pentomino),55)True# all-dead equals all-dead.
def is_cycle(grid, limit=100):
Given a single Grid , determine if its sequence of generations becomes an "oscillator", where after some point, a repeating sequence of at least two distinct grids occurs. Note that still life grids are not cycles ! Again, the chosen number of generations
to inspect (limit) may be short enough to prohibit our finding the cycle.
o Assume s:grid is a Grid , and limit is a positive integer that may default to 100.
o Hint : use your n_gens function.Alsowhat function on a previous project could be useful??
o Examples use names of provided GridStrings.
o is_cycle(build_grid(boat),5)False#still-lifesoscillators
o is_cycle(build_grid(blinker),10)True
o is_cycle(build_grid(r_pentomino),50)False
o is_cycle(build_grid(pulsar),5)True
o is_cycle(build_grid(pulsar),3)False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
