Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- const int k = 4;
- const int n = 16;
- static int[] arr = new int[k];
- static int[] free = Enumerable.Range(1, n).ToArray();
- public static void Main(string[] args)
- {
- GenerateVariationsNoRepetitions(0);
- }
- static void GenerateVariationsNoRepetitions(int index)
- {
- if (index >= k)
- {
- PrintVariations();
- }
- else
- {
- for (int i = index; i < n; i++)
- {
- arr[index] = free[i];
- Swap(ref free[i], ref free[index]);
- GenerateVariationsNoRepetitions(index + 1);
- Swap(ref free[i], ref free[index]);
- }
- }
- }
- private static void Swap<T>(ref T v1, ref T v2)
- {
- T old = v1;
- v1 = v2;
- v2 = old;
- }
- static void PrintVariations()
- {
- Console.WriteLine("(" + string.Join(", ", arr) + ")");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement