My code that I posted here returns,

  13 sw~ 3{.d
+------+------+------+
|5 10 7|5 10 7|5 10 7|
+------+------+------+

And it's what is expected. There are three windows, each one's center
being each item. Those windows' sizes are 3(maximum is 13 but there
are only 3 elements).

2007/2/1, R.E. Boss <[EMAIL PROTECTED]>:
Question remains what happens if x>#y

  13 (sw ,.&(<@,.) (]([ <@({:@]}. ({.~{.))"_ 1 ([EMAIL PROTECTED] <. ({.+}.)@] ,. 
0:>.
({.>:@-~}.)@])) >[EMAIL PROTECTED]:@[ , [EMAIL PROTECTED]@])) d
+-----------------------------+---------------------------+
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1             |||5 10 7 8 9 2 1           ||
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1 100         |||5 10 7 8 9 2 1 100       ||
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1 100 _1      |||5 10 7 8 9 2 1 100 _1    ||
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1 100 _1 4    |||5 10 7 8 9 2 1 100 _1 4  ||
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1 100 _1 4 3  |||5 10 7 8 9 2 1 100 _1 4 3||
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1 100 _1 4 3 0|||5 10 7 8 9 2 1 100 _1 4 3||
|+---------------------------+|+-------------------------+|
||0 5 10 7 8 9 2 1 100 _1 4 3|||5 10 7 8 9 2 1 100 _1 4 3||
|+---------------------------+|+-------------------------+|
||5 10 7 8 9 2 1 100 _1 4 3  |||10 7 8 9 2 1 100 _1 4 3  ||
|+---------------------------+|+-------------------------+|
||10 7 8 9 2 1 100 _1 4 3    |||7 8 9 2 1 100 _1 4 3     ||
|+---------------------------+|+-------------------------+|
||7 8 9 2 1 100 _1 4 3       |||8 9 2 1 100 _1 4 3       ||
|+---------------------------+|+-------------------------+|
||8 9 2 1 100 _1 4 3         |||9 2 1 100 _1 4 3         ||
|+---------------------------+|+-------------------------+|
||9 2 1 100 _1 4 3           ||                           |
|+---------------------------+|                           |
+-----------------------------+---------------------------+


R.E. Boss



-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Roger Hui
Verzonden: woensdag 31 januari 2007 15:37
Aan: Programming forum
Onderwerp: Re: [Jprogramming] sliding window

prefix=: (>[EMAIL PROTECTED]: }. i.)@[ {.&.> <@]
suffix=: |.&.>@prefix&.|.
sw    =: prefix , <\ , suffix



----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Tuesday, January 30, 2007 6:53 pm
Subject: Re: [Jprogramming] sliding window

> prefix=: 4 : '(->:i.-<.x%2)}.&.> <  x {.y'
> suffix=: 4 : '( >:i. <.x%2)}.&.> <(-x){.y'
> sw=: prefix , <\ , suffix
>
> d=: 5 10 7 8 9 2 1 100 _1 4 3
> z=: 5 10 7; 5 10 7 8; 5 10 7 8 9; 10 7 8 9 2; 7 8 9 2 1; 8 9 2 1
> 100; 9 2 1 100 _1; 2 1 100 _1 4; 1 100 _1 4 3; 100 _1 4 3; _1 4 3
>
>   z -: 5 sw d
> 1
>
> I am not sure what is supposed to happen if n
> is greater than the length of the data.
>
> The order of the arguments is switched based on the
> principle used for J primitive dyads:  x&func is
> expected to be a more useful function than func&y .
>
>
>
> ----- Original Message -----
> From: June Kim <[EMAIL PROTECTED]>
> Date: Tuesday, January 30, 2007 5:39 pm
> Subject: [Jprogramming] sliding window
>
> > Suppose the following data is given
> >
> >   d=: 5 10 7 8 9 2 1 100 _1 4 3
> >
> > Now suppose a verb that moves a sliding window through the data
> >
> >   d sw 5
> >
> > The size of the window is always odd. For each item in the given
> data,> the window should locate it at the middle point of the
> window. For
> > some items that's nearby boundaries, the window size could be
> smaller> than the given.
> >
> > The result should be
> >
> > 5 10 7; 5 10 7 8; 5 10 7 8 9; 10 7 8 9 2; 7 8 9 2 1; 8 9 2 1
> 100;
> > 9 2
> > 1 100 _1; 2 1 100 _1 4; 1 100 _1 4 3; 100 _1 4 3; _1 4 3
> >
> > Middle points for the window are 5, 10, 7 ..., 4, 3
> >
> > What is an easy way for sw?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
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