Created
November 4, 2014 13:44
-
-
Save andbroby/2153176eae0c42d3ff7d to your computer and use it in GitHub Desktop.
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
def warshall(matrix): | |
n = len(matrix) | |
for k in range(n): | |
for i in range(n): | |
for j in range(n): | |
if matrix[i][k] and matrix[k][j]: | |
matrix[i][j] = 1 | |
return matrix | |
matrix = [[0, 0, 0, 1], | |
[1, 0, 1, 0], | |
[1, 0, 0, 1], | |
[0, 0, 1, 0]] | |
transclosure = warshall(matrix) | |
for row in transclosure: | |
print(row) | |
#[1, 0, 1, 1] | |
#[1, 0, 1, 1] | |
#[1, 0, 1, 1] | |
#[1, 0, 1, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment