Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def has _ ship [ fleet grid: list [ 1 ist [ str ] ] , fow _ start: int, col _ start: int, ship

def has_ship[fleet grid: list[1ist[str]], fow_start: int, col_start: int,
ship_syntol: str, ship_sizer int) bool:
wauneturn True if and only if a ship that (1) uses ship_symbol as its thip
symool and (2) has length ship_size appears in fleet onid starting at
position (row start, col_start), where (rou_start, col_start) is the
top-most/luft-most correr of the ship.
If the ship has ship_size z or more and appears as both a colum and a row,
return False.
Preconditions:
=1i(i,j)==1-8rleetrrid
def has_ship(fleet_grid: list[1ist[str]], row_start; int, col_starts int, ship_symboli str, ship_size: int]=> booli
"*"Return True if and only if a ship that (1) uses ship_symbol as its ship symbol and (2) has length ship_size appaars in fleet grid starting at position (rou_start, col_start), where (row_start, col_start) is the tro-most/left nost corner of the ship.
If the ship has ship size 2 or more and appears as both a column and a row, return False.
Preconditions:
len(flaat_grid)
Ien(fleet grid[i])=len(fleetgrid) for each value of in inge(len(fleet grid))
row_start c len(fleet_grid)
ib col_start i len(fleet_grid)
MIII SHIP_SIZI = ship_size s= HAX_SHr_SIZE
fleet grid[i][5] i= ship syrbol for each of the coordinates
) Ca (rom_start =1, col_start) or
(i, j)=(row_stant, col_start -1)
when those coordinstes ape valid indexes for fleat_grid
grid =[[EYPTY,'b', EMPTY],['a','b', EMPTY],[EAPTY, EFPTY, ENPTY]] has,ship(erid,a,1,'b',2)
True
has_ship(grid, e,1,'b',1)
False
has_ship(grid,6,1,?'b',3
False
has_ship(erid,1, e,'a',1)
True has ship(erid,(:8,8,b',3}
False
image text in transcribed

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago