fork(5) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ConsoleApp1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] arr = { 1, 2, 3, 4 };
  12. IEnumerable<IEnumerable<int>> result = arr.Select(x => new List<int>() { x });
  13. for (int i = 1; i < arr.Length; i++)
  14. result = result.SelectMany(x => arr.Except(x), (x, y) => x.Concat(new int[] { y }));
  15. foreach (var item in result)
  16. {
  17. foreach (int i in item)
  18. Console.Write(i + " ");
  19. Console.WriteLine();
  20. }
  21. }
  22. }
  23. }
  24.  
Success #stdin #stdout 0.03s 15840KB
stdin
Standard input is empty
stdout
1 2 3 4 
1 2 4 3 
1 3 2 4 
1 3 4 2 
1 4 2 3 
1 4 3 2 
2 1 3 4 
2 1 4 3 
2 3 1 4 
2 3 4 1 
2 4 1 3 
2 4 3 1 
3 1 2 4 
3 1 4 2 
3 2 1 4 
3 2 4 1 
3 4 1 2 
3 4 2 1 
4 1 2 3 
4 1 3 2 
4 2 1 3 
4 2 3 1 
4 3 1 2 
4 3 2 1