RECR-P4

Every running order

Practice 4 of 6Recursion and backtracking6 tests

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

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

6 tests, not run yet
Test results
#TestResultReads · time
1Three trainsNot run
2NoneNot run
3OneNot run
4Count for 6Not run
5Input not changedNot run
68 trainsNot run