You also could consider replacing an equal last number by _ as in
rem1 =: (}:,{:+_*[:=/_2{.])&.|:
NB. much faster than (}:,{:+_*[:=/_2{.])"1
a=:10000 [EMAIL PROTECTED]
6!:2 '(}:,{:+_*[:=/_2{.])&.|: a'
0.00173723
6!:2 '(}:,{:+_*[:=/_2{.])"1 a'
0.0228713
6!:2 'rem a'
0.011968
But if you are only interested in the length of the corrected rows, than
will do
rem1=:4-([:=/_2{.])@|:
rem1 a
4 4 4 4 4 4 3 4 4 3 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...
6!:2 'rem1 a'
0.000627005
R.E. Boss
>-----Oorspronkelijk bericht-----
>Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Henry Rich
>Verzonden: maandag 20 maart 2006 1:49
>Aan: 'Programming forum'
>Onderwerp: RE: [Jprogramming] Jagged array
>
> rem =: -@:(=/"1)@:(_2&{."1) <@}."0 1 ]
> a =. 61 72 73 73 ,: 2 3 50 49
> rem a
>+--------+---------+
>|61 72 73|2 3 50 49|
>+--------+---------+
>
>However...I advise you to avoid the boxing if you can. If
>you can use the trailing 0 to indicate where a value has been
>deleted, your code will run faster.
>
>Henry Rich
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of
>> Vladimir Lazunin
>> Sent: Sunday, March 19, 2006 7:15 PM
>> To: [email protected]
>> Subject: [Jprogramming] Jagged array
>>
>> I have a matrix of integers, there are 4 columns and any
>> numberof rows. In
>> any of the rows two last numbers could be equal. If so, one should be
>> removed. I.e., for example, this:
>> 61 72 73 73
>> 2 3 50 49
>> should turn to:
>> 61 72 73
>> 2 3 50 49
>> Or, rather:
>> +--------+---------+
>> |61 72 73|2 3 50 49|
>> +--------+---------+
>> I've managed to do that for a single row by defining
>> (probably, really
>> ugly):
>> er_if =: 3 : '(y. -. 3 { y.),(3 { y.)'
>> What I need is to get rid of those trailing 0-s when I aply
>> it to the entire
>> matrix. I plan to use # on it later and I need it to return 3 or 4,
>> respectively, not always 4.
>>
>> ----------------------------------------------------------------------
>> 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