Skip to content

Instantly share code, notes, and snippets.

@pi3r0
Created November 15, 2016 10:36
Show Gist options
  • Save pi3r0/89acc3ae3ed3d4d47fcf082a0baf73ee to your computer and use it in GitHub Desktop.
Save pi3r0/89acc3ae3ed3d4d47fcf082a0baf73ee to your computer and use it in GitHub Desktop.
func solutionA(_ A : [[Int]]) -> Int {
var saddlePoints = 0;
for i in 1..<A.count - 1 {
for j in 1..<A[i].count - 1 {
let columnTest = [A[i][j-1], A[i][j], A[i][j+1]].sorted {$0 < $1};
let lignTest = [A[i-1][j], A[i][j], A[i+1][j]].sorted {$0 > $1};
if (columnTest.first! == A[i][j] && lignTest.first! == A[i][j]) {
print("Got it One \(A[i][j]) \(i) \(j) \n");
saddlePoints += 1 ;
}
if (columnTest.last! == A[i][j] && lignTest.last! == A[i][j]) {
print("Got it Two \(A[i][j]) \(i) \(j) \n");
saddlePoints += 1 ;
}
}
}
return saddlePoints;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment