Question
The code I tried to pass didn't work and I'm tired of not having this one code pass and I've copied over the code for
The code I tried to pass didn't work and I'm tired of not having this one code pass and I've copied over the code for copy paste purposes at the end:
import subprocess from project3 import*
file = open("tests3v11_sample.txt") contents = file.readlines() file.close() #class version in PROBLEM11.txt #code below from online guide #similar to 3v1 def findNeighbors(width, height, tile): width = width height = height tile = tile #main reference tile number 24 row = (tile - 1) // width col = (tile - 1) % width
top = tile - width top_lft = top - 1 top_rt = top + 1 lft = tile - 1 rt = tile + 1 bottom = tile + width btm_lft = bottom - 1 btm_rt = bottom + 1 result = " " if (row - 1 >= 0) and (col - 1 >= 0): result += str(top_lft) + " " if (row - 1 >= 0): result += str(top) + " " if (row - 1 >= 0) and (col + 1 = 0): #same row as reference tile result += str(lft) + " " if (col + 1 >= 0): result += str(rt) + " " if (row + 1 >= 0) and (col - 1 >= 0): result += str(btm_lft) + " " if (row + 1 >= 0): result += str(bottom) + " " if (row + 1 >= 0) and (col + 1
#END YOUR CODE failed = False ctr = 0 while ctr + 1
else: print "At least one test case did not pass yet." result = subprocess.check_output
Imagine that the user specifies with width and height of a grid, and provides a tile in that grid. You will write code to return all of the tiles adjacent to the tile provided by the user in string fomat separated by spaces. There should be an additional space at the end of the string you will return (this will make your algorithm easier to write). For example, on the 7x10 grid below, 16 17 18 25 30 31 32 57 58 65 tiles 24 has the neighbors "16 17 18 23 25 30 3 32 ". If a tile is at the edge of the grid, such as tile 64, we only include its adjacent neighbors 57 58 65 "). Make sure you return the tiles in sorted order like in these examples (you don't need to sort them formally, just add thenm into the string in the correct order). If a tile has no ueighbors. you should return an empty string. You may use the following formulas in your solution as needed: row-(tila -1) wicth col- (til?. 1) % width Imagine that the user specifies with width and height of a grid, and provides a tile in that grid. You will write code to return all of the tiles adjacent to the tile provided by the user in string fomat separated by spaces. There should be an additional space at the end of the string you will return (this will make your algorithm easier to write). For example, on the 7x10 grid below, 16 17 18 25 30 31 32 57 58 65 tiles 24 has the neighbors "16 17 18 23 25 30 3 32 ". If a tile is at the edge of the grid, such as tile 64, we only include its adjacent neighbors 57 58 65 "). Make sure you return the tiles in sorted order like in these examples (you don't need to sort them formally, just add thenm into the string in the correct order). If a tile has no ueighbors. you should return an empty string. You may use the following formulas in your solution as needed: row-(tila -1) wicth col- (til?. 1) % widthStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started