Here's another variation, which uses of J's "free parenthesis on the right" for verb/noun expressions:
mean=: +/ % # medianRDM=:([: (<. , >.) 0.5 * _1 + #) ([: mean {) /:~ (same test cases as before) Note that you could take this further, and eliminate two pairs of parenthesis, putting /:~ on the left side of {~ (Meanwhile note that /:~ will still be a monad while {~ is a dyad, so the significance of the ~ will be different - in one case we want the monad that it produces while in the other case we want the dyad it produces.) FYI, -- Raul On Tue, Mar 12, 2013 at 5:45 AM, Linda Alvord <lindaalv...@verizon.net> wrote: > Raul, This didn't lead anywhere new either: > > mean=: +/ % # > medianRM=:([: ([: ([: (<. , >.) -:) <:) #) ([: mean {) /:~ > medianRM 8 1 6 7 > 6.5 > medianRM > ([: ([: ([: (<. , >.) -:) <:) #) ([: mean {) /:~ > > Linda > > > -----Original Message----- > From: programming-boun...@forums.jsoftware.com > [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Raul Miller > Sent: Sunday, March 10, 2013 8:49 PM > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Find the median > > On Sun, Mar 10, 2013 at 6:29 PM, km <k...@math.uh.edu> wrote: >> The median of list 1 2 2 4 6 is 2 ("middle" value of sorted list), the > median of 2 2 4 6 is 3 (average of two "middle" values). Write a verb to > find the median of a sorted list of numbers. > > Here's one implementation of this definition of median: > > mean=: +/ % # > median=: (<.,>.)@-:@<:@# mean@:{ /:~ > > -- > Raul > ---------------------------------------------------------------------- > 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