ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# akzj's solution

## to Saddle Points in the Erlang Track

Published at May 12 2021 · 0 comments
Instructions
Test suite
Solution

Detect saddle points in a matrix.

So say you have a matrix like so:

``````    0  1  2
|---------
0 | 9  8  7
1 | 5  3  2     <--- saddle point at (1,0)
2 | 6  6  7
``````

It has a saddle point at (1, 0).

It's called a "saddle point" because it is greater than or equal to every element in its row and less than or equal to every element in its column.

A matrix may have zero or more saddle points.

Your code should be able to provide the (possibly empty) list of all the saddle points for any given matrix.

The matrix can have a different number of rows and columns (Non square).

Note that you may find other definitions of matrix saddle points online, but the tests for this exercise follow the above unambiguous definition.

## Running tests

In order to run the tests, issue the following command from the exercise directory:

For running the tests provided, `rebar3` is used as it is the official build and dependency management tool for erlang now. Please refer to the tracks installation instructions on how to do that.

In order to run the tests, you can issue the following command from the exercise directory.

``````\$ rebar3 eunit
``````

## Questions?

For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.

## Source

J Dalbey's Programming Practice problems http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

``````%% based on canonical data version 1.3.0

-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").

Input=[
[9, 8, 7],
[5, 3, 2],
[6, 6, 7]
],
Expected=[{1, 0}],

Input=[
[]
],
Expected=[],

Input=[
[1, 2, 3],
[3, 1, 2],
[2, 3, 1]
],
Expected=[],

Input=[
[4, 5, 4],
[3, 5, 5],
[1, 5, 4]
],
Expected=[{0, 1}, {1, 1}, {2, 1}],

Input=[
[6, 7, 8],
[5, 5, 5],
[7, 5, 6]
],
Expected=[{1, 0}, {1, 1}, {1, 2}],

Input=[
[8, 7, 9],
[6, 7, 6],
[3, 2, 5]
],
Expected=[{2, 2}],

Input=[
[3, 1, 3],
[3, 2, 4]
],
Expected=[{0, 0}, {0, 2}],

Input=[
[2],
[1],
[4],
[1]
],
Expected=[{1, 0}, {3, 0}],

Input=[
[2, 5, 3, 5]
],
Expected=[{0, 1}, {0, 3}],
``````-module(saddle_points).

saddle_points(_L,_Row,Col,EC,_ER,Acc) when  Col == EC ->
Acc;

saddle_points(_L,Row,Col,EC,ER,Acc) when Row == ER ->

CowList=lists:foldl(fun(X,List)->List++[lists:nth(Col+1,X)]end,[],L),
RowList=lists:nth(Row+1,L),
MinCol=lists:min(CowList),
MaxRow=lists:max(RowList),
if
MinCol == MaxRow->
true ->
end.``````