-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43d8ff9
commit 93a1df0
Showing
6 changed files
with
116 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
exercises/practice/saddle-points/.meta/Sources/SaddlePoints/Position.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
struct Position : Equatable { | ||
let row: Int | ||
let column: Int | ||
struct Position: Equatable { | ||
let row: Int | ||
let column: Int | ||
|
||
static func ==(lhs: Position, rhs: Position) -> Bool { | ||
return lhs.row == rhs.row && lhs.column == rhs.column | ||
} | ||
static func == (lhs: Position, rhs: Position) -> Bool { | ||
return lhs.row == rhs.row && lhs.column == rhs.column | ||
} | ||
} |
31 changes: 16 additions & 15 deletions
31
exercises/practice/saddle-points/.meta/Sources/SaddlePoints/SaddlePointsExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
struct SaddlePoints { | ||
static func saddlePoints(_ matrix: [[Int]]) -> [Position] { | ||
var saddlePoints = [Position]() | ||
for (rowIndex, row) in matrix.enumerated() { | ||
for (columnIndex, element) in row.enumerated() { | ||
if isSaddlePoint(matrix, rowIndex, columnIndex) { | ||
saddlePoints.append(Position(row: rowIndex + 1, column: columnIndex + 1)) | ||
} | ||
} | ||
static func saddlePoints(_ matrix: [[Int]]) -> [Position] { | ||
var saddlePoints = [Position]() | ||
for (rowIndex, row) in matrix.enumerated() { | ||
for (columnIndex, element) in row.enumerated() { | ||
if isSaddlePoint(matrix, rowIndex, columnIndex) { | ||
saddlePoints.append(Position(row: rowIndex + 1, column: columnIndex + 1)) | ||
} | ||
return saddlePoints | ||
} | ||
} | ||
return saddlePoints | ||
} | ||
|
||
static private func isSaddlePoint(_ matrix: [[Int]], _ rowIndex: Int, _ columnIndex: Int) -> Bool { | ||
let element = matrix[rowIndex][columnIndex] | ||
let row = matrix[rowIndex] | ||
let column = matrix.map { $0[columnIndex] } | ||
return row.allSatisfy { $0 <= element } && column.allSatisfy { $0 >= element } | ||
} | ||
static private func isSaddlePoint(_ matrix: [[Int]], _ rowIndex: Int, _ columnIndex: Int) -> Bool | ||
{ | ||
let element = matrix[rowIndex][columnIndex] | ||
let row = matrix[rowIndex] | ||
let column = matrix.map { $0[columnIndex] } | ||
return row.allSatisfy { $0 <= element } && column.allSatisfy { $0 >= element } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters