Enter "comb" to see the tacit version of my verb: comb ([ = [: +/"1 [: #: [: i. 2 ^ ]) ([: |. [: I. #) [: #: [: i. 2 ^ ] Linda
-----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Linda A Alvord Sent: Saturday, September 26, 2015 11:48 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Generate Complete Graphs comb=: 13 :'(x=+/"1 #:i.2^y) ([:|.[:I.#) #:i.2^y' 2 comb 5 0 1 0 2 0 3 0 4 1 2 1 3 1 4 2 3 2 4 3 4 3 comb 4 0 1 2 0 1 3 0 2 3 1 2 3 -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich Sent: Saturday, September 26, 2015 11:12 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Generate Complete Graphs ; <@({. ,. }.)\.@i. 5 (#~ </"1) (#: i.@(*/)) 2 $ 5 Henry Rich On 9/26/2015 9:24 AM, 'Jon Hough' via Programming wrote: > Sorry, the second verb should be > > getEdges =: 3 : 0 > if. 1 > # y do. > > else. > h =. 1{.y > t =. 1}.y > ((h&,)"0 t ), getEdges t > end. > ) > > (changed getNodes to getEdges) > > > -------------------------------------------- > On Sat, 9/26/15, 'Jon Hough' via Programming <programm...@jsoftware.com> wrote: > > Subject: [Jprogramming] Generate Complete Graphs > To: "Programming Forum" <programm...@jsoftware.com> > Date: Saturday, September 26, 2015, 10:16 PM > > 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 > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm