On 5/17/07, eesuk <[EMAIL PROTECTED]> wrote:
I'm looking for nice one-liner code of "Floyd-Warshall" algorithm.
MP=: <./ . +~^:_
is good for all pairs shortest paths problem,
but ~O(n^3 log n).
I think you mean:
MP=: (<. <./ .+~)^:_
Floyd-Warshall algorithm is O(n^3).
I have this:
-----------------
FWx=: 3 : 0
for_k. i.#y do.
y=.k (]<.{"1 +/ {)y
end.
)
So, my question: How can I get a one-liner by using { and k in
for-loop implicitly?
Well... here's a fairly direct translation of FWx to a tacit
one-liner:
FW1=: [: > <"[EMAIL PROTECTED]@# (] <. {"1 +/ {)&.>/@, <
This iterates over k in a different direction, but other than that,
it's a mechanical translation of FWx.
I don't know if there's a better approach.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm