The problem
A set of trains must leave one after another. Return every possible running order: every permutation of items, as a list of lists. The orders may be in any order.
orders([1, 2, 3])
# [[1, 2, 3], [1, 3, 2], [2, 1, 3],
# [2, 3, 1], [3, 1, 2], [3, 2, 1]]
orders([]) # [[]]
itertools.permutations is switched off. Do not change items. The tests sort your answer before comparing it.
Limits
- Up to 8 items, all different.
Builds on RECR-4 Subsets and permutations.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
6 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | Three trains | Not run | |
| 2 | None | Not run | |
| 3 | One | Not run | |
| 4 | Count for 6 | Not run | |
| 5 | Input not changed | Not run | |
| 6 | 8 trains | Not run |