diff --git a/exercises/saddle-points/README.md b/exercises/saddle-points/README.md index f9b8edaff..7f098e90e 100644 --- a/exercises/saddle-points/README.md +++ b/exercises/saddle-points/README.md @@ -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 @@ -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 @@ -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. diff --git a/exercises/saddle-points/saddle-points.example.ts b/exercises/saddle-points/saddle-points.example.ts index 75d5ad539..d845e6102 100644 --- a/exercises/saddle-points/saddle-points.example.ts +++ b/exercises/saddle-points/saddle-points.example.ts @@ -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}) } } } diff --git a/exercises/saddle-points/saddle-points.test.ts b/exercises/saddle-points/saddle-points.test.ts index 525f22050..ea587cc6d 100644 --- a/exercises/saddle-points/saddle-points.test.ts +++ b/exercises/saddle-points/saddle-points.test.ts @@ -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], @@ -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], @@ -41,9 +41,22 @@ 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], @@ -51,4 +64,38 @@ describe('Saddle Points', () => { [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) + }) })