Skip to content

Instantly share code, notes, and snippets.

@andbroby
Created November 4, 2014 13:44
Show Gist options
  • Save andbroby/2153176eae0c42d3ff7d to your computer and use it in GitHub Desktop.
Save andbroby/2153176eae0c42d3ff7d to your computer and use it in GitHub Desktop.
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