Thanks M
Sent from my iPad > On 7 Jan 2021, at 19:25, Justin Paston-Cooper <[email protected]> wrote: > > In the list < _1 0 1 2, _1 is less than 0, but 0 1 2 are not. > Therefore this is not a valid maximally contiguous run. The property > here is <&0. A run is a maximally contiguous substring where all > elements have the same property value. In this case, there are exactly > two property values, namely 0 and 1. There may be properties with more > values. > > My application: Given a merged time series of the price of the same > thing in two separate places, find maximal runs where the ratio of > prices is always more than 1. Less than 1 can also be interesting. > > On Thu, 7 Jan 2021 at 19:01, 'Michael Day' via Programming > <[email protected]> wrote: >> >> Both this approach and Raul's appear to answer your requirement, but I'm >> wondering >> what result you require for this slightly altered input: >> l1 =: 0 _1 0 1 2 _1 4 5 _6 >> >> If you need maximally contiguous runs, I'd have thought this would be a >> preferred solution: >> 0 ; _1 0 1 2 ; _1 ; 4 5 ; _6 >> ┌─┬────────┬──┬───┬──┐ >> │0│_1 0 1 2│_1│4 5│_6│ >> └─┴────────┴──┴───┴──┘ >> since the run _1 0 1 2 is of length 4. >> >> However, both suggested methods return this >> (<;.1~ (~:_,}:)@p) l1 NB. xash >> ┌─┬──┬─────┬──┬───┬──┐ >> │0│_1│0 1 2│_1│4 5│_6│ >> └─┴──┴─────┴──┴───┴──┘ >> p F l1 NB. RM >> ┌─┬──┬─────┬──┬───┬──┐ >> │0│_1│0 1 2│_1│4 5│_6│ >> └─┴──┴─────┴──┴───┴──┘ >> >> I suppose my problem is that I don't see the point of property p ! >> >> Cheers, >> >> Mike >> >> >>> On 07/01/2021 09:29, xash wrote: >>> l =: _1 _2 0 1 2 _1 4 5 _6 >>> p =: <&0 >>> (<;.1~ (~:_,}:)@p) l >>> ┌─────┬─────┬──┬───┬──┐ >>> │_1 _2│0 1 2│_1│4 5│_6│ >>> └─────┴─────┴──┴───┴──┘ >>> >>> >>>> On Thu Jan 7, 2021 at 10:12 AM CET, Justin Paston-Cooper wrote: >>>> I am sure this has been asked and formulated somewhere else. I don't >>>> know what the name of it is. >>>> >>>> Let G be a set of groups. Given a list `l =: l_1 ... l_2` and a >>>> property `p` such that `p l_i` is in G, I would like a function `f` >>>> which partitions `l` into the successive maximally contiguous runs >>>> `r_1 ... r_k` such that for each `i`, `r_i` is a substring of `l`, >>>> there exists one `g` in G such that all `p r_ij = g` and the >>>> concatenation of `r_1 ... r_k` is equal to the original `l`. >>>> >>>> Examples: >>>> >>>> l = _1 _2 0 1 2 _1 4 5 _6` >>>> p = <&0 >>>> >>>> f l = _1 _2 ; 0 1 2 ; _1 ; 4 5 ; _6 >>>> >>>> ;. gets close, but one would need to specify where groups end possibly >>>> by comparing successive pairs of applications of `p`. Those positions >>>> would somehow need to be indicated as frets. >>>> >>>> /. gets close, but concatenates separate runs within the same group. >>>> >>>> Is this trivial, or should I write my own code for this? >>>> ---------------------------------------------------------------------- >>>> For information about J forums see http://www.jsoftware.com/forums.htm >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> >> >> -- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus >> >> ---------------------------------------------------------------------- >> 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
