5
0
The Monkey has swung home to find his tree all in pieces.
He likes order and scoops up all his 'tree-parts' and sets them out in 3 groups.
The Monkey's 3 nested lists:
STEP = [['S', '1', 'B', '3'], ['S', '3', 'B', '11'], ['S', '5', 'B', '12'], ['S', '4', 'B', '13'], ['S', '2', 'B', '14']]
TRANSITION = [['T', '2', 'B', '4'], ['T', '7', 'B', '4'], ['T', '3', 'S', '4'], ['T', '5', 'S', '5'], ['T', '1', 'S', '2'], ['T', '8', 'S', '2'], ['T', '6', 'S', '1'], ['T', '9', 'S', '2'], ['T', '4', 'S', '1'], ['T', '10', 'S', '1']]
BRANCH = [['B', '3', 'T', '1'], ['B', '3', 'T', '7'], ['B', '4', 'S', '3'], ['B', '11', 'T', '3'], ['B', '11', 'T', '5'], ['B', '12', 'T', '6'], ['B', '12', 'T', '8'], ['B', '13', 'T', '4'], ['B', '13', 'T', '9'], ['B', '14', 'T', '2'], ['B', '14', 'T', '10']]
Each element holds information as such:
# Example
STEP[0] = ['S', '1', 'B', '3']
Where:
- 'S' is the
STEPtype - '1' is the
STEPnumber id - 'B' is the linked
BRANCHtype - '3' is the linked
BRANCHnumber id
Starting from a STEP the data is all linked, so using the linked reference you can find the next element and the next until another STEP is reached.
This is some parameters of the data:
STEPSare connected to singleBRANCHESBRANCHESare connected to one or moreTRANSITIONSTRANSITIONScan be connected to a singleBRANCHorSTEP
The BRANCH data can have a fork where a single BRANCH id has one or more options for TRANSITIONS.
Re-create this monkey's tree (nested list format is fine) in the shortest way possible (he is not a fan of long instructions):
[S1]
|
B3|_________
| |
[T1] [T7]
| |
| B4|
| |
[S2] [S3]
And list all the routes on this tree:
Routes = [[S1, B3, T1, S2], [S1, B3, T7, B4, S3]]
UPDATE: This is Code-golf and from the data given you need to output the display of the tree ( This can be different from my example but requires the same elements to be displayed in any format) and as you cycle through the problem to output all the possible routes as a BONUS.
1I assume you want [tag:code-golf] if your winning criteria is shortest code. I'm also confused what the input/output is. Do we just need to output the content of the last two codeblocks? – Jo King – 2020-02-28T04:27:05.330
Pretty new here, still getting the etiquette down. Yes Code-golf and from the data given you need to output the display of the tree ( This can be different from my example but requires the same elements to be displayed in any format) and as you cycle through the problem to output all the possible routes as a BONUS. – leopardxpreload – 2020-02-28T04:48:38.003
1
Welcome to Code Golf! What are acceptable outputs for the tree? Can it just be nested lists? Or does it need to be some
– Arnauld – 2020-02-28T14:43:59.703ascii-art? (in which case this tag should be added and the format should be specified some more)@arnauld - thank you! It can just be nested lists - okay, fantastic Ill update that – leopardxpreload – 2020-02-28T22:34:57.690
Welcome to CCPG! I enjoy graph theory related challenges. Some questions: 1. The input seems a bit laborious; can we simply take a single list of tuples
(x,y)wherexandyare strings? E.g.:[('S1', 'B3'), ('B3', 'T1'), ('B3, 'T7'), ...]? 2. Can we assume that the graph described by the input is a single rooted tree? – Chas Brown – 2020-02-29T06:32:21.990