I have a couple of verbs to represent a complete (undirected) graph as a list
of edges. Clearly there are "N choose 2" edges that need to be generated. This
is my code
complete =: 3 : 0
nodes =. i. y
getEdges nodes
)
getEdges =: 3 : 0
if. 1 > # y do.
else.
h =. 1{.y
t =. 1}.y
((h&,)"0 t ), getNodes t
end.
)
e.g. I can get the 10 edges of the graph K5 by doing
complete 5
My above code is ugly however. To be specific, it seems too imperative for J,
and the first part of the if. do. in getEdges doesn't return anything which
seems ugly.
I would like to know if there is a more J-like, terse way to do this.
Regards,
Jon
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm