PC_Meister
Board Regular
- Joined
- Aug 28, 2013
- Messages
- 72
Hello,
I have been scratching my head over this for a while but i can't seem to find the answer maybe because I have not done any recursive functions in a very long time . I have the following columns.
[TABLE="class: grid, width: 250, align: center"]
<tbody>[TR]
[TD]Begin[/TD]
[TD]Shape1[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape2[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape1[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape3[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape2[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape4[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape4[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape6[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape3[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape5[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape5[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape7[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape5[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape8[/TD]
[/TR]
</tbody>[/TABLE]
I am trying to write a recursive subroutine that will generate the unique sequences showing the connectivity of the sequences, so for example for the case shown above we will get 3 sequences:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Shape1[/TD]
[TD]Shape2[/TD]
[TD]Shape4[/TD]
[TD]Shape6[/TD]
[/TR]
[TR]
[TD]Shape1[/TD]
[TD]Shape3[/TD]
[TD]Shape5[/TD]
[TD]Shape7[/TD]
[/TR]
[TR]
[TD]Shape1[/TD]
[TD]Shape3[/TD]
[TD]Shape5[/TD]
[TD]Shape8[/TD]
[/TR]
</tbody>[/TABLE]
A few observations I have noted:
I was able to find a solution to this particular problem using nested loops but given that the length of the sequence of shapes is not constant, recursion appear as the most viable way. Any pointers will be great. Thanks!
I have been scratching my head over this for a while but i can't seem to find the answer maybe because I have not done any recursive functions in a very long time . I have the following columns.
[TABLE="class: grid, width: 250, align: center"]
<tbody>[TR]
[TD]Begin[/TD]
[TD]Shape1[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape2[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape1[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape3[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape2[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape4[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape4[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape6[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape3[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape5[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape5[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape7[/TD]
[/TR]
[TR]
[TD]Begin[/TD]
[TD]Shape5[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]Shape8[/TD]
[/TR]
</tbody>[/TABLE]
I am trying to write a recursive subroutine that will generate the unique sequences showing the connectivity of the sequences, so for example for the case shown above we will get 3 sequences:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Shape1[/TD]
[TD]Shape2[/TD]
[TD]Shape4[/TD]
[TD]Shape6[/TD]
[/TR]
[TR]
[TD]Shape1[/TD]
[TD]Shape3[/TD]
[TD]Shape5[/TD]
[TD]Shape7[/TD]
[/TR]
[TR]
[TD]Shape1[/TD]
[TD]Shape3[/TD]
[TD]Shape5[/TD]
[TD]Shape8[/TD]
[/TR]
</tbody>[/TABLE]
A few observations I have noted:
- the number of unique sequences is equal to the number of shapes that occur only once in the column(Shape6, Shape7, Shape8 in this case). These will be the terminating shapes for a sequence
- Each sequence will always start by the shape in the first row (Shape1 in this case)
I was able to find a solution to this particular problem using nested loops but given that the length of the sequence of shapes is not constant, recursion appear as the most viable way. Any pointers will be great. Thanks!