Objectives

Students will be able to:

  • understand that computer programs can follow different paths.
  • understand logical operators such as >, <, ==, !=
  • understand the different symbols for drawing a flowchart.

Perfect balance

A grid is known to have perfect balance if one of its diagonals are all zeros and the other diagonal are all ones ie:

 

Here are two examples of grids that do not have perfect balance:

 

A function, perfectBalance, needs to be written to determine if a two-dimensional array of integers has a perfect balance.

It accepts a two-dimensional array of integers as a parameter.

It returns true, if there is a perfect balance and false otherwise.

pre-condition: the array always has one more row than columns. The top right diagonal always has zeros, the bottom left has ones.

post-condition: the array remains unchanged after processing.

Code this function.

Side note

This is a good test of your computational thinking!