I have a nested list like this:
test1 = {{1, 3}, {1, 4}, {1, 7}, {2, 1}, {3, 5}, {4, 1}, {5, 2}, {6, 1}, {7, 6}}
I want to join the lists together depending on if the first element is equal to the last element as to end up with:
test2 = {{1, 3, 3, 5, 5, 2, 2, 1}, {1, 4, 4, 1}, {1, 7, 7, 6, 6, 1}}
Eventually I will want to delete duplicate elements in each list ending up with:
test3 = {{1, 3, 5, 2, 1}, {1, 4, 1}, {1, 7, 6, 1}}
I tried Join with constraints or GatherBy but I cant seem to get it right. Also note that first elements are always unique except if its a 1.
Any help is much appreciated!
{{1, 2}, {2, 3}, {2, 4}, {2, 5}, {4, 2}}
? $\endgroup${{1, 3}, {3, 5}, {5, 2}, {2, 1}, {1, 4}, {4, 1}, {1, 7}, {7, 6}, {6, 1}}
in which case there is only one "partition". Please clarify. $\endgroup$FindPostmanTour@Graph[DirectedEdge @@@ test]
. I mean, your firsttest
definition. Please don't use the same symbol to refer to different things in your questions as it makes comments much difficult to write (like this one) $\endgroup$