Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

read_coords (s): Given a GridString s, read through it and create a list of int pairs for all live cells Each pair is a (row,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

read_coords (s): Given a GridString s, read through it and create a list of int pairs for all live cells Each pair is a (row, column) coordinate. If the rows don't all have the same number of spots indicated, or if any unexpected characters are present, this function returns None. Must be ordered by lowest row and lowest column when rows match. o Assume: s is a GridString o Hint: s.split) is your friend. What should you split by? o read_coords("o..n.00 ") read-coords("inino.. .00 ") [(8,0), (1,1), (1,2)] # ignore blank lines o get_dimensions (s): Given a GridString s, find out how many rows and columns are represented in the GridString, and return them as a tuple: (numrows, numcols). Remember that any blank lines must be ignored (skipped). If the rows don't all have the same number of items in them, or any unexpected characters are present, this function returns None. o Assume: s is a GridString o get_dimensions ("O. . .00 ") o get-dimensions("00000 00 ") o get dimensions(" oo .. .o no.In..In ") None (5,2) #not rectangular ! # note ignored blank lines build_empty_grid(height, width): Given positive int values for the height and width of a grid, create a Grid that has False values at each location (representing dead cells) o Assume: height and width are positive integers o build, empty-grid (2,3) [[False, False, False], [False, o build-empty-grid (1,4) build, empty-grid(3,1) [[False], [False], [False]] o build-empty-grid(1,3) [[False, False, False]] False, False]] [[False, False, False, Falsell build_grid(s): Given a GridString s, determine the dimensions, build a grid of that size, and make alive each cell that should be alive. Assume: s is a GridString Hint: try to use read_coords, get_dimensions, and build_empty_grid in your solution. o build grid("o.. .oo ") o o [False, True], False, True]] [[True, [[False, False], False], [True, True, False, True, False, False True, [True, [False, True]] o build-grid(".. .o 00 ") o build grid("00.0..") show-grid (grid, live-'0' , dead-'') : Given a Grid, and the option to indicate what representation . to use for live and dead cells, create the GridString that has no blank lines in it and represents the indicated grid. o Assume: grid is a Grid; live and dead are strings. o Hint: You'll likely want to call print (show_grid (someGrid)) when trying it out. o show_grid(I[True, False, False], [False, True, True]]) o show_grid([[False, False], [True, True]]) o show_grid([[False, False], [True, True]], 'A', '#) o show grid([]) "O..n.00 n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+4 Develop and deliver the CCT program.

Answered: 1 week ago