Skip to content

Sync saddle-points to version 1.5.0 #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions exercises/saddle-points/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Detect saddle points in a matrix.
So say you have a matrix like so:

```text
0 1 2
1 2 3
|---------
0 | 9 8 7
1 | 5 3 2 <--- saddle point at (1,0)
2 | 6 6 7
1 | 9 8 7
2 | 5 3 2 <--- saddle point at column 1, row 2, with value 5
3 | 6 6 7
```

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

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
Expand All @@ -23,15 +23,17 @@ 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.

## Setup

Go through the setup instructions for TypeScript to
install the necessary dependencies:
Go through the setup instructions for TypeScript to install the necessary
dependencies:

http://exercism.io/languages/typescript
[https://exercism.io/tracks/typescript/installation](https://exercism.io/tracks/typescript/installation)

## Requirements

Expand All @@ -49,11 +51,16 @@ Execute the tests with:
$ yarn test
```

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing `xit` to
`it`.

## Source

J Dalbey's Programming Practice problems [http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html](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.

It's possible to submit an incomplete solution so you can see how others have
completed the exercise.
2 changes: 1 addition & 1 deletion exercises/saddle-points/saddle-points.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SaddlePoints {
for (let i = 0; i < maximumRowValues.length; i++) {
for (let j = 0; j < minimumColumnValues.length; j++) {
if (maximumRowValues[i] === minimumColumnValues[j]) {
resultPoints.push({row: i, column: j})
resultPoints.push({row: i + 1, column: j + 1})
}
}
}
Expand Down
59 changes: 53 additions & 6 deletions exercises/saddle-points/saddle-points.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SaddlePoints from './saddle-points'
describe('Saddle Points', () => {
it('Can identify single saddle point', () => {
const expected = [
{row: 1, column: 0}
{row: 2, column: 1}
]
expect(SaddlePoints.saddlePoints([
[9, 8, 7],
Expand All @@ -28,11 +28,11 @@ describe('Saddle Points', () => {
])).toEqual(expected)
})

xit('Can identify multiple saddle points', () => {
xit('Can identify multiple saddle points in a column', () => {
const expected = [
{row: 0, column: 1},
{row: 1, column: 1},
{row: 2, column: 1}
{row: 1, column: 2},
{row: 2, column: 2},
{row: 3, column: 2}
]
expect(SaddlePoints.saddlePoints([
[4, 5, 4],
Expand All @@ -41,14 +41,61 @@ describe('Saddle Points', () => {
])).toEqual(expected)
})

xit('Can identify multiple saddle points in a row', () => {
const expected = [
{row: 2, column: 1},
{row: 2, column: 2},
{row: 2, column: 3}
]
expect(SaddlePoints.saddlePoints([
[6, 7, 8],
[5, 5, 5],
[7, 5, 6]
])).toEqual(expected)
})

xit('Can identify saddle point in bottom right corner', () => {
const expected = [
{row: 2, column: 2}
{row: 3, column: 3}
]
expect(SaddlePoints.saddlePoints([
[8, 7, 9],
[6, 7, 6],
[3, 2, 5]
])).toEqual(expected)
})

xit('Can identify saddle points in a non square matrix', () => {
const expected = [
{row: 1, column: 1},
{row: 1, column: 3}
]
expect(SaddlePoints.saddlePoints([
[3, 1, 3],
[3, 2, 4]
])).toEqual(expected)
})

xit('Can identify that saddle points in a single column matrix are those with the minimum value', () => {
const expected = [
{row: 2, column: 1},
{row: 4, column: 1}
]
expect(SaddlePoints.saddlePoints([
[2],
[1],
[4],
[1]
])).toEqual(expected)
})

xit('Can identify that saddle points in a single row matrix are those with the maximum value', () => {
const expected = [
{row: 1, column: 2},
{row: 1, column: 4}
]
expect(SaddlePoints.saddlePoints([
[2, 5, 3, 5]
])).toEqual(expected)
})
})