forked from exercism/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
saddle-points: sync tests expected results with problem-specification…
…s and update example solution.
- Loading branch information
Showing
2 changed files
with
20 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
def saddle_points(m): | ||
if not m: | ||
return set() | ||
if any(len(r) != len(m[0]) for r in m): | ||
def saddle_points(matrix): | ||
if not matrix: | ||
return [{}] | ||
if any(len(row) != len(matrix[0]) for row in matrix): | ||
raise ValueError('irregular matrix') | ||
mmax = [max(r) for r in m] | ||
mmin = [min(c) for c in zip(*m)] | ||
points = [(i+1, j+1) for i in range(len(m)) | ||
for j in range(len(m[0])) if mmax[i] == mmin[j]] | ||
mmax = [max(row) for row in matrix] | ||
mmin = [min(col) for col in zip(*matrix)] | ||
points = [{"row": index + 1, "column": col_index + 1} for index in range(len(matrix)) | ||
for col_index in range(len(matrix[0])) if mmax[index] == mmin[col_index]] | ||
|
||
return set(points) | ||
return points or [{}] |
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