combnu=: [: ,.^:(1...@$) [:; [:(,.&.><@;\.)/ (($,:)i.)
NB. combinations with non-unique elements
mmd=: 4 : 0
z0=. (i.x) * y <....@%&<: x
z1=. <:y - {:z0
z2=. (z1 combnu >:x) (+/@:{)"1 _ |.|:(>:/&i.>:)x
(<,z0) +"1&.> (#...@~."1 </.])z2
)
3 mmd 8
+-----+-----+
|0 3 6|0 3 7|
|1 4 7|0 4 7|
+-----+-----+
$&.>11 mmd 55
+----+------+------+------+------+
|5 11|100 11|450 11|600 11|210 11|
+----+------+------+------+------+
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Raul Miller
> Verzonden: maandag 17 augustus 2009 14:05
> Aan: Programming forum
> Onderwerp: [Jprogramming] minmax differences
>
> require 'stats'
>
> Given a result from comb pick the entries which
> maximize the minimum difference between
> any two adjacent entries.
>
> (#~ [: (= >./) [: <./"(1) 2 -~/\"1 ])3 comb 8
> 0 3 6
> 0 3 7
> 0 4 7
> 1 4 7
>
> Then from this result, pick the entries which
> maximize the next highest difference between
> any two adjacent entries, repeating until
> every remaining difference has been considered.
>
> In this case (3 comb 8), I would want
>
> 0 3 7
> 0 4 7
>
> I should probably just code this up explicitly
> but I had hoped I could derive this result
> tacitly, but I keep running up against the
> 2 argument limit, for tacit expressions.
>
> Does anyone see an obvious approach, here?
>
> Thanks,
>
> --
> 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