fork(2) download
  1. import copy
  2. cnt = 0
  3.  
  4. def ModifySublist(Ls, idx, value):
  5. res = copy.deepcopy(Ls)
  6. res[idx].append(value)
  7. return res
  8.  
  9. def InsertSublist(Ls, idx, value):
  10. res = copy.deepcopy(Ls)
  11. res.insert(idx, [value])
  12. return res
  13.  
  14. def GenDists(AList, Level, Limit):
  15. global cnt
  16. if (Level==Limit):
  17. print( AList)
  18. cnt += 1
  19. else:
  20. for i in range(len(AList)):
  21. GenDists(ModifySublist(AList, i, Level), Level + 1, Limit)
  22. GenDists(InsertSublist(AList, i, Level), Level + 1, Limit)
  23. GenDists(InsertSublist(AList, len(AList), Level), Level + 1, Limit)
  24.  
  25. GenDists([], 0, 3)
  26. print(cnt)
Success #stdin #stdout 0.02s 27704KB
stdin
Standard input is empty
stdout
[[0, 1, 2]]
[[2], [0, 1]]
[[0, 1], [2]]
[[1, 2], [0]]
[[2], [1], [0]]
[[1], [0, 2]]
[[1], [2], [0]]
[[1], [0], [2]]
[[0, 2], [1]]
[[2], [0], [1]]
[[0], [1, 2]]
[[0], [2], [1]]
[[0], [1], [2]]
13