Skip to content

Instantly share code, notes, and snippets.

@MASaraji
MASaraji / warshall-floyd:transitive closure
Last active May 7, 2021 08:51
warshal-floyd with permutations
bin_matrix = [[0, 1, 0, 0,0], [1, 0, 1, 0,0], [0, 0, 0, 1,1], [0,0, 0, 0,0],[0,0,0,0,0]]
from itertools import product
a=product(range(len(bin_matrix)),repeat=3)
a=filter(lambda a:bin_matrix[a[0]][a[1]] and bin_matrix[a[1]][a[2]],a)
@MASaraji
MASaraji / warshall-floyd
Created May 6, 2021 21:21
warshall algorithm
bin_matrix = [[0, 1, 0, 0], [1, 0, 1, 0], [0, 0, 0, 1], [0,0, 0, 0]]
length=range(len(bin_matrix))
for k in length:
for i in length:
for j in length:
if bin_matrix[i][k] and bin_matrix[k][j]:
bin_matrix[i][j] = 1