The problem came up when swing trading was explained to me and I was wondering how to recognize the ups & downs of a stock.
The solutions of xash and Rehr had some good ideas, ({. i.@>:) for example. Here is mine, polished a bit, after grown over the days: Foo=:{{, |: (#~1 <#@~.S:0)"1 \:~(<;.2"1~ 1,.~ (}.<}:)`(}.>}:)`:0) y}} Ups and downs are treated separately and the sets are put in the right order. Then all boxes with one occurrence are omitted, and after transposing, the array can be raveled. Foo ?.@#~20 +-----+--------+---+---+----------+------------+---------+----+---+---+ |14 16|16 8 6 5|5 8|8 6|6 16 16 19|19 13 12 3 1|1 9 12 17|17 0|0 9|9 5| +-----+--------+---+---+----------+------------+---------+----+---+---+ Foo ?.@#~25 +----+---+---+-------+-----+-----+----+---+---+----+-------+----+----+-------+----+----+----+----+------+---+ |19 6|6 8|8 6|6 10 23|23 16|16 21|21 1|1 9|9 8|8 22|22 13 1|1 14|14 2|2 17 20|20 9|9 15|15 7|7 22|22 4 2|2 9| +----+---+---+-------+-----+-----+----+---+---+----+-------+----+----+-------+----+----+----+----+------+---+ Foo ?.@#~30 +--------+------+----+--------+--------+---------+----+-----+-----+----+----+-----+-----+----+-------+-------+-------+--------+-----+-----+ |24 26 28|28 6 5|5 28|28 16 16|16 16 26|26 19 3 2|2 13|13 11|11 19|19 2|2 27|27 10|10 19|19 5|5 17 27|27 19 7|7 24 28|28 27 14|14 22|22 21| +--------+------+----+--------+--------+---------+----+-----+-----+----+----+-----+-----+----+-------+-------+-------+--------+-----+-----+ R.E Boss -----Original Message----- From: Programming <programming-boun...@forums.jsoftware.com> On Behalf Of R.E. Boss Sent: donderdag 20 mei 2021 17:15 To: programm...@jsoftware.com Subject: Re: [Jprogramming] ups & downs Your missing last bucket can simply be repaired with (I.,#)@, But even then you run into the same error as xash with ?.@#~30 where the subsequence ... 28 16 16 26 ... should be split in 28 16 16 and 16 16 26, before continuing with 26 9 3 2. R.E. Boss -----Original Message----- From: Programming <programming-boun...@forums.jsoftware.com> On Behalf Of Hauke Rehr Sent: donderdag 20 mei 2021 15:23 To: programm...@jsoftware.com Subject: Re: [Jprogramming] ups & downs so this is what I came up with but it’s still missing the last bucket (9 5) and it doesn’t read as well as xash’s version I strongly expect one could do better than to {.+i.@-.@-/ but I just don’t know how (let alone how to {~ < < of that better) ff =: (<@{~ 2 <&<&({. + i.@-.@(-/))"1@:]\ 1 I.@, 0 = 2+/\ 2&((<->)/\)) Am 20.05.21 um 14:20 schrieb Hauke Rehr: > correction: of course, it’s 2&((<->)/\) > > Am 20.05.21 um 14:15 schrieb Hauke Rehr: >> you can also use (2 (< - >)/\) instead of (}: (<+_1*>) }.) I think >> that way it’s going more in the “appreciated” direction :) >> >> Am 20.05.21 um 13:49 schrieb xash: >>> f=:((#~ 1&|.) ,&.> <;.1~) 0 1, 0= 2+/\ }: (<+_1*>) }. >>> >>> The first part assigns _1 to elements that are greater than the next >>> one, and 1 to elements that are less than the next one. Where _1 1 >>> or 1 _1 occur, a new group starts. Thus 0= 2+/\. >>> >>> This gets us the starting indices for <;.1. Because the borders >>> should be included, we prepend each element that is before a group >>> start `(#~ 1&|.)` to that group `,&.>` (thus the unusual `0 1,` for the >>> group starts). >>> -------------------------------------------------------------------- >>> -- For information about J forums see >>> http://www.jsoftware.com/forums.htm >>> >> > -- ---------------------- mail written using NEO neo-layout.org ---------------------------------------------------------------------- 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