Decision logic for sequence

Hello everyone on the forum.
I’m having a difficulty in Dynamo, which I’ve tried different ways to solve and I searched a lot on the forum to help, but nothing went right and I decided to ask for help from those who know or help me walk, because my logic is paralyzed.

In this case, it would have to locate my elements A B C from Dynamo’s list, leaving it as it is in the table.


My table has a specific position for ABC, the A always at 1, 4, 7, 10, 13, 16, 19, 22
the “B” in 2, 5, 8… the “C” in 3, 6, 9…
If it has AB, it would be some position of the free “A” and the free “B” on the side.

Everything has been read from a Dynamo list, like the screenshot.

In this case it would read the “A” and place it in positions 1, 4… as it is in yellow.
Then I would read the “AB” and place it in the free positions at 10 and 11, 13 and 14, 16 and 17, as it is in blue.
Then I would read the “B” and place it in the free positions in 2, as it is in orange.
Then I would read the “BC” and place it in the free positions at 5 and 6, 7 and 8 as it is in green.,
Then I would read the “C” and place it in the free positions at 3, 12, 15… as it is in red,
Then I would read the “CA” and place in the free positions in “CA” free that you have, 21 and 22, as it is in purple.
Then I would read the “ABC” (in this case it doesn’t have) and put it in an “ABC”…

I would like to output a “text”, which I will later put as a parameter, in this case: “position 1”,“position 2”…

Is it possible to create this decision logic in dynamo or in phyton?

You need to fundamentally rethink your problem and its data structure as its irrational. For example, why is AB ignored in 1,2 and 4,5 but grouped from 10,11? The same with BC? Why does ABC not exist when actually…it does?

1 Like

Hello @Thomas_Mahon thanks, I appreciate the feedback.

In the case as mentioned:
“why is AB ignored in 1.2 and 4.5 but grouped from 10.11?”
The AB can be grouped in any position that contains the free AB, it could be 1.2 in the case even though it would have no influence on the result.
As for what you mentioned
Why does ABC not exist when actually…it does?
It means that there may be the case “ABC” that must be considered, it just doesn’t exist in this example I’m showing

I’m sorry if you got confused how I formulated the question initially, but I tried to describe as much as possible because it is a (for me) complex case.

Possible in Python if you can detect the grouping system. In the case if your data you have used colour to do this, so in a data set you would actually need a second parallel list with that aspect in a data sense.

You could use the zip statement to iterate using a for loop, and each time you check a result, you would check the previous one’s colour against the current. If it is the same colour, append to previous letter and move forward one item. If at any point the colour changes, yield the current letter object to a new list, then reset that variable. From there you just group by key using the data as the key.

It’s a very wacky data structure, but I think I get it.

If the above makes no sense let me know and I’ll have a crack in Python later on.

Assuming it’s always only ABC based

st00 = ["A","A","A","AB","AB","AB","B","BC","BC","C","C","C","C","CA"];
st01 = List.Sort(st00);
st02 = List.GroupByKey(st01,String.Substring(st01,0,1))["groups"];
sqA1 = 1..#List.Count(st01)..3;
stA1 = List.Flatten(sqA1 + (0..String.Length(st02[0])-1),-1);
sqB1 = List.SetDifference(2..#List.Count(st01)..3, stA1);
stB1 = List.Flatten(sqB1 + (0..String.Length(st02[1])-1),-1);
sqC1 = List.SetDifference(3..#List.Count(st00)..3,List.Flatten([stA1,stB1],-1));
stC1 = List.Flatten(sqC1 + (0..String.Length(st02[2])-1),-1);
st03 = List.Flatten([stA1,stB1,stC1],-1);
st04 = List.Chop(st03,String.Length(st01));