NB. x : (# of nodes);r NB. y : travel pairs NB. a : adjacency matrix NB. d : all pair distance matrix
length2=: 4 : 0
'N r'=.x
a=.(<.|:)1 (;/r)}_ 0{~ =i.N
d=.((<./ . +)^:_)~ a
d{~;/y
)
r=:0 2, 0 1, 2 3, 2 5, 2 7, 5 6,: 1 4
(8;r) length2 7 6,4 7,4 6,:0 6
3 4 5 3
---
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
