6 years ago there was a similar problem for which I produced a rather
efficient solution
http://www.jsoftware.com/pipermail/general/2004-May/017490.html, which was
further improved by Hui
http://www.jsoftware.com/pipermail/general/2004-May/017503.html to 

rankx  =: i.~ (] - {) /:@/:

strikeb2=: 4 : 0
 x #~ (rankx x) >: ((~.y) i. x) { (#/.~y),0
)

   1 2 3 4 1 1 strikeb2 1 2 1
3 4 1


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens June Kim
> Verzonden: zaterdag 17 april 2010 16:00
> Aan: Programming forum
> Onderwerp: [Jprogramming] remove elements (with repetition allowed)
> 
> How would you implement "takeout"(Less with equally valued cell numbers
> significant) in the following test cases?
> 
> assert 1 2   -:&(/:~) 1 2 3 takeout 3
> assert (,:1) -:&(/:~) 1 1 1 takeout 1 1
> assert 1 3 4 -:&(/:~) 1 2 3 4 1 1 takeout 1 2 1
> assert 1 2 3 -:&(/:~) 1 2 3 3 2 takeout 3 2
> 
> My first quick implementation(without much thought):
> 
> keyind=:([:< i...@# ,. ])/.~
> takeout =: {:"1...@-.&(;@:keyind)
> 
> I would appreciate simpler and more elegant solutions.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to