Given an array of numbers, like ?.@#~20 14 16 8 6 5 8 6 16 16 19 13 12 3 1 9 12 17 0 9 5
there is always a sequence of (non-strict) ups & downs, like 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 +-----+--------+---+---+----------+------------+---------+----+---+---+ |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| +-----+--------+---+---+----------+------------+---------+----+---+---+ Well, this is the way I prefer to have the ups & downs, where they share their border terms. Which verb makes this transformation? Elegance, as always, is appreciated, correctness is a must, efficiency a blessing. Some testcases: 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm