Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Imagine that the user specifies with width and height of a grid, and a tile in t

ID: 3844811 • Letter: I

Question

Imagine that the user specifies with width and height of a grid, and a tile in that grid. Find the "mirror-mirror" of that tile, that is, if you folded the grid in half, and then folded it in half again, the tile that the original tile overlaps is its mirror-mirror (think of folding a sheet of paper in half, and then folding it in half again along the other axis). For example, for a 7x10 grid:


the mirror-mirror of tile 27 would be tile 44.

You may use the following formulas in your solution as needed:

row = (tile - 1) // width

column = (tile - 1) % width

Testing Your Code

When you are ready, right-mouse-click to save the file driver to the same directory as your project3.py. Also download and save the tests3v9_sample.txt to the same directory. You can then run your code against our test cases through the terminal with the command"

python driver3_sample.py

This will test your code on the same test cases as Marmoset, and give you a report. Once you've passed as many tests as you can, upload your submission to Marmoset using the instructions at the bottom of the page.

Code Templates


Download the code project3.py answer template for this assessment. Right-mouse click and save the file as project3.py.

Its contents are as follows:

def getMirrorMirror(width, height, tile1):
    width = width
    height = height
    tile1 = tile1


    #YOUR CODE GOES HERE (indented)

    return "fixme"
    #END YOUR CODE
Download the supporting file SystemCall for this assessment. Right-mouse click to save the file as SystemCall.java.

Download the supporting file code support files for this assessment. Right-mouse click and save the file as code.py.

1 2 3 4 5 6 7 8 9 14 15 16 22 23 24 25 26 27 28 29 32 36 40 43 44 48 50 56 57 63 64 65 66 67 68 69 70

Explanation / Answer

I have created and developed the Python Program for "mirror-mirror" of the tile based on a user input of a specified width and height,. I have added the comments for each part of the code and the final output of it.

Let me explain you in step-by-step procedure:-

Step-1:

The initial part is to calculate the formulaes based on the row and column of a grid which is having pre-defined classes and functions,

Example:-

row = (tile-1) //width

column =(tile-1) % width

Step-2:

The next part is to declare the function in python using the 'def' keyword based on three parameters i.e, Width, Height and the Tile1.

Example:-

def getMirrorMirror (width, height, tile1)

Step-3:

The final part is to explicitly declare the variables inside the function by calculating the absolute result for the given parameters in the function call.

Example:-

result = abs (dx+dy)

Python Program:-

# Created a getMirrorMirror function with three parameters width, height and tile1

def getMirrorMirror (width, height, tile1):

# Assigns the value for each parameters

width = width
height = height
tile1 = tile1

# Declared the formulae for row and column values   

mirrorRow = (tile1 - 1) //width
mirrorColumn = (tile1 - 1)%width
mirrorXAxis = max (abs (mirrorColumn-mirrorColumn2),0)
mirrorYAxis = max (abs (mirrorRow-mirrorRow2)-1,0)

# Defined the result value in the 'mirrorFinalResult'

mirrorFinalResult = abs (mirrorXAxis+mirrorYAxis)
if mirrorFinalResult == 1:
return 0
elif mirrorFinalResult == 2:
return 1
else:
return mirrorFinalResult
     
# Finally returns the result as a grid     
     
return mirrorFinalResult