t,:v
1.26 3.78 6.3 10.08 11.34 12.6 13.86 15.12 16.38 17.64
0 20 40 60 80 100 525 321 248 259
wat
4 : 0
ctl=. 0,~ _1+(}.-}:) x
avg=. 0,~ 0.5 * (}.+}:) y
ins=. ctl #&.> (2 < ctl) {"_1 avg,.y
;}:,y;"0 ins
)
t wat v
|domain error: wat
| ins=.ctl #&.>(2<ctl){"_1 avg,.y
On Tue, Nov 20, 2012 at 9:06 PM, Raul Miller <[email protected]> wrote:
> On Mon, Nov 19, 2012 at 5:38 PM, Alexander Epifanov <[email protected]> wrote:
>> Unfortunately cannot resolve problem, which could be easy resolved with loop:
>> t=: 1 3 6 10 11 12
>> v=: 0 20 40 60 80 100
>>
>> i=: _1+(}.-}:) t
>> i NB. its just distance between numbers
>> 1 2 3 0 0 0
>>
>> And now the main problem for me, because I have to modify v array:
>> if i = 0 then nothing
>> if i = 1 or i = 2 then insert average value (for 1) and two values for 2
>> if i = 3 then insert previous value
>
> This specification seems odd. What if i contains some other value? I
> am going to assume that values greater than 3 will be given the same
> treatment as values where you need 3 copies, and that negative values
> will not appear in i
>
>> so, we have to fill missed values in t and v:
>> t=: 1 3 6 10 11 12
>> v=: 0 20 40 60 80 100
>>
>> should be:
>> t2: 1 2 3 4 5 6 7 8 9 10 11 12 (ok, its just full index now)
>> v2: 0 10 20 30 30 40 40 40 40 60 80 100
>> ^ inserted by condition: 10; 30 30; 40 40 40
>>
>> Could you please help how to resolve it better? I suppose I can rotate
>> |:t,:v and then fold it one-by-one, but I think it is not good
>> solution.
>
> I am not sure if this is better, but it meets the specifications you
> have provided:
>
> wat=: 4 :0
> ctl=. 0,~ _1+(}.-}:) x
> avg=. 0,~ 0.5 * (}.+}:) y
> ins=. ctl #&.> (2 < ctl) {"_1 avg,.y
> ;}:,y;"0 ins
> )
>
> t wat v
> 0 10 20 30 30 40 40 40 40 60 80 100
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
Regards,
Alexander.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm