Assessment 2: Decision Making
These assessments will be focused on performing mathematical calculations on grids. Why grids?
- Understanding how to navigate grids is fundamental in many computer computer science domains. For example,
if you are doing deep learning on computer vision problems, you'll need to feel comfortable working with
images composed of rows and columns of pixels. Similarly, analyzing the activations of voxels from fMRI
data also involves a three-dimensional grid.
- It is not unusual to be given such a grid-manipulation problem during a coding interview. These problems
require very little setup, are easy to envision, focus on problem solving rather than memorization of
details of any particular programming language, and can be deceptively tricky! Fortunately, we'll have
plenty of practice with them on this assessment.
- Almost no programming knowledge is required, just mathematical operators and if-else statements.
Therefore, not is it a good time in the semester to introduce these exercises, but they also serve to
equalize somewhat the playing field for those who have programmed before, and those who haven't.
I hope you have fun with these problems and view them as puzzles. Remember, if you're stuck for more than 20 minutes
on a homework problem such as these, post a message to Piazza (and see the questions and answers there while you
wait for a response)! We love to answer questions on Piazza!
Instructions
This assessment is designed to be completed in fifty minutes or less. Your code must work on any valid inputs to receive credit.
Complete the template below such that you will provide code to solve the following problem. When you are satisfied with your solution,
you should upload your solution, you should upload it to Blackboard. Each assessment comes with test cases that you can
run before submitting your assignment, so you know how you're doing on it.
Imagine that the user specifies with width and height of a grid, and provides a tile in that grid. You will write code to determine if the
tile is within the first, second, third, or fourth quadrant on the grid, labelled as follows:
Your code should return one of the four integers to indicate which quadrant the tile is on. For example, on an 4x5 grid, tile 18 is in quadrant 4.
If the tile straddles a quadrant, it should be assigned to be the higher, and/or more left, quadrant. For example, on a 5x5 grid, tile
13 (the center tile) would be in quadrant 1.
Draw these two grids out on a sheet of paper to help you visualize the problem.
You may use the following formulas in your solution as needed:
row = (tile - 1) / width
column = (tile - 1) % width
Code Template and Test cases
Download the code template.