> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Raul Miller
> Verzonden: dinsdag 18 augustus 2009 0:37
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] minmax differences
> 
(...)
> 
> (R.E. Boss's approach also seems to be relevant, but I
> need to study his some more.)
> 

Let me try to help you.

mmd=: 4 : 0
z0=. (i.x) * y <....@%&<: x
z1=. <:y - {:z0
z2=. (z1 combnu >:x) (+/@:{)"1 _ |.|:(>:/&i.>:)x
(<,z0) +"1&.> (([:>./ 2 -~/\ ])"1 </. ])z2
)

Looking for a maximum minimum distance between the numbers of an item of  x
comb y  , it is obvious that this is achieved in  z0 , since that
max-min-distance is equal to  y <....@%&<: x  .
All the other items with this max-min-distance differ at most  z1  , which
is essentially  x |&<: y  . All these differences are  z2  .
Now  z2  is boxed according to its maximum distance and than  z0  is added
to it.
Each box contains the items with the required minimum distance and the
maximum distance 0,1,2,.... more.
This is shown by

   ([:~. ([:(<./,>./) 2 -~/\ ])"1)&.> 11 mmd 55
+---+---+---+---+---+
|5 5|5 6|5 7|5 8|5 9|
+---+---+---+---+---+

The advantage of the method is that  x comb y  is not needed.
Compare

   11 ! 55
119653565850

or even worse

   50 ! 102
3.9192407e29

with 

   $&.> 50 mmd 102
+----+--------+-------+-----+
|4 50|20923 50|2450 50|49 50|
+----+--------+-------+-----+

   ts' 50 mmd 102'
0.11643995 43856640


R.E. Boss



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

Reply via email to