This is evil and easy:
median2 =:([: (+/%#) ([:}.}:)^:(2<#)^:_) : [: NB. Zsbán
median /:~ 8 1 6 7
6.5
These two have the potential to be annoying, but I don't know yet:
mean=: +/ % #
median=: (<.,>.)@-:@<:@# mean@:{ /:~ NB. Raul
midpt=: -:@<:@#
median=: -:@(+/)@((<. , >.)@midpt { /:~) NB. Ric
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of km
Sent: Monday, March 11, 2013 3:12 PM
To: [email protected]
Subject: Re: [Jprogramming] Find the median
Evil! --Kip
Sent from my iPad
On Mar 11, 2013, at 5:11 AM, Zsbán Ambrus <[email protected]> wrote:
> On Sun, Mar 10, 2013 at 11:29 PM, km <[email protected]> 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.
>
> Ok, here's an evil variant:
>
> median =: ([: (+/%#) }.@}:^:(2<#)^:_) : [:
>
>
> --
> Ambrus
> ----------------------------------------------------------------------
> 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