2. Definition:
1. a point on a curved surface at which the curvatures in two mutually
perpendicular planes are of opposite signs
2. a value of a function of two variables which is a maximum with respect to one
and a minimum with respect to the other
(Merriam-Webster)
Uses:
Used in industry for optimization & decision making e.g. optimal cost/profit point
In Game Theory the saddle point represents the best strategy for both players
3. Exercism Instructions
Detect saddle points in a given matrix where the numeric value of an element is;
• The highest value in the row and,
• The lowest value in the column
The matrix may have zero or multiple saddle points
The matrix can have a different number of rows and columns (non-square)
For example;
0 1 2
0 9 8 7
1 5 3 2
2 6 6 7
<= Saddle point at (1,0)
5 is the highest number in its row and,
5 is the lowest value in the column
4. Exercism Test Suite
1. new method instantiates an object of the Matrix class
2. expecting a return array of the integer series of a row
3. matrix values are given in string format with new line
character separating the rows
4. Expecting a return array of the integer series of a column
5. expecting a return array representing the coordinates of the
saddle point in the Matrix
6. has other tests for “no saddle point” and “multiple saddle
points”
Comments
5. Exercism Solution
attr reader for three return vales
string manipulation to split rows and elements, mapped to array of integers
transpose row to give columns
private method to return saddle point
6. Exercism Solution
nested loop through elements of row and column
Checks whether each element is a saddle point via private method “saddle_point?”
if element is a saddle point push to “sp” array
return the sp array