In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 14th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #09 exercise sheet]


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

(in this class you are expected to write a solution that uses recursion - mooshak will not force it, but that should be your goal)

[IP089] Delivery Route

Philip J. Fry has been assigned a tricky delivery route. He must visit a list of planets, starting at any planet of his choosing, visit every other planet exactly once, and return to the starting planet. However, Fry's human brain isn't great at figuring out all possible routes, so he needs your help to generate all possible orders for his journey!

The Problem

Write a function visit(planets) that receives a list of planets. The function should return a list containing all possible routes, where each route starts and ends with the same planet and visits every other planet exactly once in between.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ |planets| ≤ 8       number of planets

Example Function Calls Example Output
output = visit(["earth", "neptune"])
print(sorted(output))

print()

output = visit(["earth", "mars", "saturn"]) 
print("output is of type", type(output))
print("output has size:", len(output))
for x in sorted(output): print(x)
[['earth', 'neptune', 'earth'], ['neptune', 'earth', 'neptune']]

output is of type <class 'list'>
output has size: 6
['earth', 'mars', 'saturn', 'earth']
['earth', 'saturn', 'mars', 'earth']
['mars', 'earth', 'saturn', 'mars']
['mars', 'saturn', 'earth', 'mars']
['saturn', 'earth', 'mars', 'saturn']
['saturn', 'mars', 'earth', 'saturn']

Introduction to Programming (CC1024)
DCC/FCUP - University of Porto