Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11. public class Program
  12. {
  13.  
  14. const int k = 4;
  15. const int n = 16;
  16.  
  17. static int[] arr = new int[k];
  18. static int[] free = Enumerable.Range(1, n).ToArray();
  19.  
  20. public static void Main(string[] args)
  21. {
  22. GenerateVariationsNoRepetitions(0);
  23. }
  24.  
  25. static void GenerateVariationsNoRepetitions(int index)
  26. {
  27. if (index >= k)
  28. {
  29. PrintVariations();
  30. }
  31. else
  32. {
  33. for (int i = index; i < n; i++)
  34. {
  35. arr[index] = free[i];
  36. Swap(ref free[i], ref free[index]);
  37. GenerateVariationsNoRepetitions(index + 1);
  38. Swap(ref free[i], ref free[index]);
  39. }
  40. }
  41. }
  42.  
  43. private static void Swap<T>(ref T v1, ref T v2)
  44. {
  45. T old = v1;
  46. v1 = v2;
  47. v2 = old;
  48. }
  49.  
  50. static void PrintVariations()
  51. {
  52. Console.WriteLine("(" + string.Join(", ", arr) + ")");
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement