[Jprogramming] rank trouble
R.E. Boss
r.e.boss at planet.nl
Sun Jun 3 02:30:36 HKT 2012
What about
e ((]-.]-.[))&(20 $]) pi
3 1 1 2 3 1 1 2 3 1
with
e (,.@;)&([:/:~ 20 $]) pi
+---------------------------------------+
|1 1 1 1 2 2 2 2 2 3 3 7 7 7 8 8 8 8 8 8|
+---------------------------------------+
|1 1 1 1 1 2 2 3 3 3 4 4 5 5 5 5 6 6 9 9|
+---------------------------------------+
Obviously wrong.
We had a similar question in 2004: http://www.jsoftware.com/pipermail/general/2004-May/017427.html
The question here appears to be the intersection of two multisets or bags http://en.wikipedia.org/wiki/Multiset
Conform http://www.jsoftware.com/pipermail/general/2004-May/017490.html one should take the minimum of the nubcounts and
reconstruct the intersection from that.
im=:intrsct_mltsts=: 4 : 0 NB. intersection of multisets
nbint =. x ([-.-.)&~. y
x (nbint #~ <. &(nbint ((i.~ {.) { {:@]) ]))&([:|:({.,#)/.~) y
)
e im&(20 $]) pi
2 2 1 1 1 1 3 3
e im&(20 $])~ pi
3 3 1 1 1 1 2 2
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: programming-bounces at jsoftware.com [mailto:programming-bounces at jsoftware.com] Namens Linda Alvord
> Verzonden: zaterdag 2 juni 2012 11:24
> Aan: 'Programming forum'
> Onderwerp: Re: [Jprogramming] rank trouble
>
>
> pi=: 3 1 4 1 5 9 2 6 5
> e=: 2 7 1 8 2 8 1 8 3
>
> pi (]-.]-.[) e
> 2 1 2 1 3
> e ([ -. -.) pi
> 2 1 2 1 3
>
> Since there is only one 2 in the nine digits of pi , isn't the only
> correct one?
>
> e (]-.]-.[) pi
> 3 1 1 2
>
> Linda
>
>
> -----Original Message-----
> From: programming-bounces at jsoftware.com
> [mailto:programming-bounces at jsoftware.com] On Behalf Of Alexander Mikhailov
> Sent: Friday, June 01, 2012 1:35 PM
> To: programming at jsoftware.com
> Subject: Re: [Jprogramming] rank trouble
>
>
> -----
> Without the "nub" gives an arguably more correct answer:
>
> pi (]-.]-.[) e
> 2 1 2 1 3
> e (]-.]-.[) pi
> 3 1 1 2
> -----
>
> Why not
>
> e ([ -. -.) pi
> 2 1 2 1 3
> ?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list