Shouldn't your result be

5; 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; 3 

where the 5 at the start and the 3 at the end are added? 
They are the centre of a window of 1. 
This is also in accordance with the middle points you gave: 5, 10, 7 ..., 4,
3

But then the solution is simple:
        the middle points are given by d 
        and the lengths of the windows are given by

   <./5,(,:|.)(+:+1:)i.#d
1 3 5 5 5 5 5 5 5 3 1


If you want the windows boxed then 

   5(<;._3 ([EMAIL PROTECTED],[,{:@]) ((,:-@|.)@(2&|#])@[EMAIL PROTECTED]) 
(<@{."0 _)"1 ]) d
+-+------+----------+----------+---------+-----------+------------+---------
---+------------+------+-+
|5|5 10 7|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|_1 4 3|3|
+-+------+----------+----------+---------+-----------+------------+---------
---+------------+------+-+

is a (first) solution, with thanks to McCormick who brought up <;._3

R.E. Boss



-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens June Kim
Verzonden: woensdag 31 januari 2007 2:39
Aan: Programming forum
Onderwerp: [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

Reply via email to