CS 1110: Introduction to Programming
Spring 2017
In-class exercise — Pseudocode


Purpose: Practice problem solving and write pseudocode

For this exercise, you may work alone or with 1-2 of your neighbors. Consider the following problems and write pseudocode to solve the problems.


Problem #1

Imagine that the user specifies the width of a grid, as well as a tile. You will return either "True" or "False" depending on whether or not the tile is along the diagonal of the square grid. For example, on a 7x7 grid, assuming the tile numbers (starting at the top-left corner) are 1, 2, 3, ..., 49

1 2 3 4 5 6 7
8
15
22 23 24 25 26 27 28
29 30
36
43

all yellow tiles are on the diagonal.

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

row = (tile - 1) // width

col = (tile - 1) % width


Problem #2

Imagine that the user specifies the width of a grid, as well as a tile. You will return either "True" or "False" depending on whether or not the tile is along the edge of grid. For example, on a 7x8 grid, assuming the tile numbers (starting at the top-left corner) are 1, 2, 3, ..., 56

1 2 3 4 5 6 7
8
15
22 23 24 25 26 27 28
29 30
36
43
50

all yellow tiles are on the edge.

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

row = (tile - 1) // width

col = (tile - 1) % width


Problem #3

Imagine that the user specifies the width and height of a grid, as well as a tile. You will return either "True" or "False" depending on whether or not the tile is in the middle row of the grid. For example, on a 7x8 grid, assuming the tile numbers (starting at the top-left corner) are 1, 2, 3, ..., 56

1 2 3 4 5 6 7
8
15
22 23 24 25 26 27 28
29 30
36
43
50

all yellow tiles are in the middle row, as a grid with an even height has two middle rows. If the grid has an odd height, there is only one middle row.

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

row = (tile - 1) // width

col = (tile - 1) % width


Problem #4

Imagine that the user specifies with width and height of a grid. You will return a string that represents all ordered tiles that make up the corners of the grid, with three tiles to a corner. You will return a string where each tile has a space after it (this will simplify your algorithm). For example, on a 7x10 grid, assuming the tile numbers (starting at the top-left corner) are 1, 2, 3, ..., 70

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

you would return the string "1 2 6 7 8 14 57 63 64 65 69 70 ". If the board doesn't have a width or height of at least four, you should return the tiles of all the edges. Under such cases, you want to avoid putting duplicate tiles in your strings.

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

row = (tile - 1) // width

col = (tile - 1) % width