#### PC_Meister

##### Board Regular

- Joined
- Aug 28, 2013

- Messages
- 72

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.

Begin | Shape1 |

End | Shape2 |

Begin | Shape1 |

End | Shape3 |

Begin | Shape2 |

End | Shape4 |

Begin | Shape4 |

End | Shape6 |

Begin | Shape3 |

End | Shape5 |

Begin | Shape5 |

End | Shape7 |

Begin | Shape5 |

End | Shape8 |

<tbody>

</tbody>

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:

Shape1 | Shape2 | Shape4 | Shape6 |

Shape1 | Shape3 | Shape5 | Shape7 |

Shape1 | Shape3 | Shape5 | Shape8 |

<tbody>

</tbody>

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!