### 1. splitting to sublist - HELLPPPP

- Posted by begin 2 months ago
- 339 views

Hi, I have a problem that I some can not solve, left alone elegantly. I hope some in the forum has some code that will solve the task. I have for ex.:

{{1000,90},{1000,90},{1000,90},{1002,70},{1000,90},{1000,90},{1002,70}} {{1000,90},{1000,90},{1000,90},{1000,70},{1000,90},{1000,90},{1000,70}} {{1000,90},{1002,90},{1002,90},{1002,70},{1002,90},{1002,90},{1002,70}}

where

1000 = and 1002 = or

the other numbers are a cf's, between 1 and 100 The first item in the list will always be an and (1000). The list can be unlimited long. It can consist of all and’s or the first and and followed by all or’s. usually the list is dispersed with or’s.

The list has to be restructured to a new list with sublists for ex.

{{1000,90},{1002,80},{1002,90},{1002,90},{1002,90},{1002,80},{1002,90},{1002,90},{1002,80}} {{1000,90},{1000,80},{1000,90},{1000,90},{1000,90},{1000,80},{1000,90},{1000,90},{1000,80}} {{1000,90},{1002,80}}, {1000,90}, {{1000,90},{1002,80}}, {1000,90}, {{1000,90},{1002,80}} {{1000,90},{1002,80},{1002,90},{1002,90}} {{1000,90},{1002,80}}, {1000,90}, {{1000,90},{1002,80}}

anybody an idea or even some code? thanks in advance

### 2. Re: splitting to sublist - HELLPPPP

- Posted by _tom (admin) 2 months ago
- 320 views

Is there a way to re-phrase the problem? I do not understand what you are asking for.

_tom

### 3. Re: splitting to sublist - HELLPPPP

- Posted by Spock 2 months ago
- 312 views

I think I get.. nope. I don't. Sorry..

Spock

### 4. Re: splitting to sublist - HELLPPPP

- Posted by petelomax 2 months ago
- 300 views

You're not really giving us very much to go on there, are you sunshine?

Just for a laugh, and with a ** massive load** of guesswork, the best I can manage:

function restructure(sequence s, sequence sublens) sequence res = {} integer idx = 1 for i=1 to length(sublens) do integer sublen = sublens[i] if sublen then sequence sub = s[idx..idx+sublen-1] sub[1][1] = 1000 for j=2 to sublen do sub[j][1] = 1002 end for res = append(res,sub) end if idx += max(sublen,1) end for return res end function ?restructure({{1000,90},{1002,80},{1002,90},{1002,90},{1002,90},{1002,80},{1002,90},{1002,90},{1002,80}},{2,1,0,2,1,2}) ?restructure({{1000,90},{1000,80},{1000,90},{1000,90},{1000,90},{1000,80},{1000,90},{1000,90},{1000,80}},{4,2,1,2})

output:

{{{1000,90},{1002,80}},{{1000,90}},{{1000,90},{1002,80}},{{1000,90}},{{1000,90},{1002,80}}} {{{1000,90},{1002,80},{1002,90},{1002,90}},{{1000,90},{1002,80}},{{1000,90}},{{1000,90},{1002,80}}}

### 5. Re: splitting to sublist - HELLPPPP

- Posted by begin 2 months ago
- 283 views

thank you all for your replies. i thought i described i well - but you are all correct.

petelomax:

thank you for the code, this is almost what i need.

object val = {{1000,90},{1002,80},{1002,90},{1002,90},{1002,90},{1002,80},{1002,90},{1002,90},{1002,80}} object ors = {} for i=1 to len do if val[i][1] = 1002 then ors &= i end if end for

i find the or's and they are:

ors = {2,3,4,5,6,7,8,9}

for anther case,

val = {{1000,90},{1002,80},{1000,90},{1000,90},{1002,80},{1000,90},{1000,90},{1002,80}} ors = {2,5,8}

and that will unfortunately not work.

on another side i had an ssd crash of my drive c: (is all of the ssd) while editing with edita. the computer froze and edita (installed on another drive that works fine) left all the files (open tabs) filled with zeros. a lot of work lost, i was doing a ceemd and had it running, what a s..t. as soon as i get to that again, i will share that. it is really neat stat analysis.

### 6. Re: splitting to sublist - HELLPPPP

- Posted by petelomax 2 months ago
- 272 views

and that will unfortunately not work.

and we still have no idea why.

### 7. Re: splitting to sublist - HELLPPPP

- Posted by begin 2 months ago
- 261 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.

### 8. Re: splitting to sublist - HELLPPPP

- Posted by petelomax 2 months ago
- 236 views

i can up with the following, but don't how to really fix it.

You were pretty close, I think, just a single > that needed to be >=. Try this:

function restructure(object orgseq) object ors={}, merge={} integer i=1, tstart=1, len=length(orgseq) while i <= len do tstart = i if orgseq[i][1] = 1002 then if i < len and orgseq[i+1][1] = 1002 then while (i <= len) and (orgseq[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 orgseq[i+1][1] != 1002 then while (i < len) and orgseq[i+1][1] != 1002 do i += 1 end while if tstart <= i then -- if i > len 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

i am sorry i can nor really explain that or i am doing it very badly.

I can now imagine why you might be struggling. Here is my attempt to explain the problem, as I understand it:

Given a sequence of 'and'/'or' elements, which must start with 'and', collect any consecutive runs of 'or' along with their previous 'and', and any consecutive runs of 'and' excluding those lumped in with an 'or' run, as separate groups. eg { and,and, and,or,or, and } -- (spaces added are mine alone) => {{and,and},{and,or,or},{and}}

And here is my attempt at that:

function get_next(sequence s, integer done, integer and_or) for i=done+1 to length(s) do if s[i][1]=and_or then return i end if end for return 0 end function function restructure(sequence s) sequence res = {} integer done = 0, next if s[1][1]!=1000 then ?9/0 -- sanity check (must start with 'and') end if while done<length(s) do next = get_next(s,done,1002) if next=0 then exit end if if next>done+2 then -- add a run of {and,and,and} -- (not including the one just before -- the or/1002 that we just found) res = append(res,s[done+1..next-2]) done = next-2 end if next = get_next(s,next,1000) if next=0 then exit end if -- add a run of {and,or,or,or} -- (up to but not including the -- and/1000 that we just found) res = append(res,s[done+1..next-1]) done = next-1 end while -- add last run res = append(res,s[done+1..len]) return res end function

HTH, Pete

### 9. Re: splitting to sublist - HELLPPPP

- Posted by begin 2 months ago
- 215 views

pete:

yes, your description is correct. i solved the problem differently - ugly as hell, so i will take yours. thank you so very much!!!

richard