Re: splitting to sublist - HELLPPPP
- Posted by begin May 30, 2018
- 1211 views
i can up with the following, but don't how to really fix it.
function restructure(object orgseq) object ors={}, merge={} integer i=1, tstart=1 while i <= len do tstart = i if val[i][1] = 1002 then if i < len and val[i+1][1] = 1002 then while (i <= len) and (val[i][1] = 1002) do i += 1 end while end if if tstart <= i then if i > len then ors = append(ors, {1002, tstart-1, len}) else ors = append(ors, {1002, tstart-1, i}) end if end if elsif i <= len and val[i+1][1] != 1002 then while (i < len) and val[i+1][1] != 1002 do i += 1 end while if tstart <= i then if i > len then ors = append(ors, {1000, tstart, len}) else ors = append(ors, {1000, tstart, i-1}) end if end if end if i += 1 end while return ors end function
for the sequence:
{{1000,90},{1002,80},{1000,90},{1000,70},{1000,90},{1000,90},{1000,70},{1000,70}}it returns
{{1002,1,2},{1000,3,7}}but it should be
{{1002,1,2},{1000,3,8}}
where
{1002,1,2} start sequence index to - including sequence index
an or carries a preceding and with it
other sequences are
--object val = {{1000,90},{1000,90},{1000,90},{1002,70},{1000,90},{1000,90},{1002,70}} --object val = {{1000,90},{1002,80},{1000,90},{1000,90},{1002,80},{1000,90},{1000,90},{1002,80}} --object val = {{1000,90},{1000,90},{1000,90},{1000,70},{1000,90},{1000,90},{1000,70}} --object val = {{1000,90},{1000,90},{1000,90},{1000,70},{1000,90},{1000,90},{1002,70}} --object val = {{1000,90},{1002,80},{1002,90},{1002,90},{1002,90},{1002,80},{1002,90},{1002,90},{1002,80}}
so for the sequence
{{1000,90},{1002,80},{1000,90},{1000,90},{1002,80},{1000,90},{1000,90},{1002,80}}it returns
{{1002,1,2},{1000,3,3},{1002,4,5},{1000,6,6},{1002,7,8}}
which is correct
i am sorry i can nor really explain that or i am doing it very badly.