Last active
May 10, 2021 15:17
-
-
Save farooqkz/d061b467e3fa06044672da68d1d1600b to your computer and use it in GitHub Desktop.
Warshall algorithm calculating transitive closure
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
// Code by Rust beginner, Farooq Karimi Zadeh | |
// Under CC0 1.0 | |
// Warning! Code might not be idiomatic | |
fn main() { | |
let mut bin_matrix = [ | |
[0, 1, 0, 0], | |
[1, 0, 1, 0], | |
[0, 0, 0, 1], | |
[0, 0, 0, 0] | |
]; | |
const N:u32 = 300_000; | |
for _dummy in 0..N { | |
for k in 0..bin_matrix.len() { | |
let the_clone = bin_matrix; | |
for (i, row) in bin_matrix.iter_mut().enumerate() { | |
for (j, value) in row.iter_mut().enumerate() { | |
if *value == 0 { | |
*value = the_clone[i][k] & the_clone[k][j]; | |
} | |
} | |
} | |
} | |
} | |
println!("{:?}", bin_matrix); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://gist.github.com/farooqkz/a6d6ac3cacdf06af1907952888acc5c2 for Python version