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
STEP
type - '1' is the
STEP
number id - 'B' is the linked
BRANCH
type - '3' is the linked
BRANCH
number 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:
STEPS
are connected to singleBRANCHES
BRANCHES
are connected to one or moreTRANSITIONS
TRANSITIONS
can be connected to a singleBRANCH
orSTEP
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.
Notes:
- This is a single-rooted tree
- You may use a different format for input but please explicitly state the input format in your solution
ascii-art
? (in which case this tag should be added and the format should be specified some more) \$\endgroup\$(x,y)
wherex
andy
are 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? \$\endgroup\$