On Thu, Sep 29, 2011 at 1:02 PM, Lettow, Kenneth <[email protected]> wrote:
> I did notice that Raul's explicit version gives a different answer from the
> brute force version. The difference is that the explicit version substituted
> the larger existing value for a missing value that fell exactly between 2
> existing values.
>
> nearValBrute=: ({."1 {~ |: i."_1 <./)@:|@(-/ 1 i.@+ >./)
>
> inds=: [: i. 1 + {:
> poss=: (,{.) {~ _1 0 +/ ] I. inds
> nearValOrdered =: |:@poss {~"_1 [: (|: i."_1 <./) inds |@-"1 poss
>
> nearValExplicit=: 3 :0
> inds=. i. 1 + {: y
> poss=. (y,{.y) {~ 0 _1 +/ y I. inds
> (|:poss) {~"_1 (|: i."_1 <./) |inds -"1 poss
> )
>
> (nearValBrute,nearValOrdered,:nearValExplicit) 1 2 5 9
> 1 1 2 2 5 5 5 5 9 9
> 1 1 2 2 5 5 5 5 9 9
> 1 1 2 2 5 5 5 9 9 9
Yes... I had pasted in an early copy of nearValExplicit
If you change
poss=. (y,{.y) {~ 0 _1 +/ y I. inds
to
poss=. (y,{.y) {~ _1 0 +/ y I. inds
it should be consistent with the other versions.
Sorry about that.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm