Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Triangle
//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 { static void log(int[] arr) { //log("Array size: " + arr.Length); //log(); Console.Write("[" + String.Join(" ", arr) + "]"); } // get all unique/distinct permutations // // var arr = new int[] { 1, 2, 3, 4, 5 }; // var result = GetAllUniquePermutations(arr, 2); // // count = 2 => // 1, 2 // 1, 3 // 1, 4 // 1, 5 // // 2, 3 // 2, 4 // 2, 5 // // 3, 4 // 3, 5 // // 4, 5 static IEnumerable<IEnumerable<T>> GetAllUniquePermutations<T>(IEnumerable<T> items, int count){ int i = 0; foreach (var item in items){ if (count == 1){ yield return new T[] { item }; }else{ foreach (var result in GetAllUniquePermutations(items.Skip(i + 1), count - 1)) { yield return new T[] { item }.Concat(result); } } i++; } } public static void Main(string[] args) { var array = Enumerable.Range(1, 5).ToArray(); Console.WriteLine("Original array:"); log(array); Console.WriteLine(); Console.WriteLine(); var allUniquePermutations = GetAllUniquePermutations(array, 3); Console.WriteLine("All possible permutations:"); foreach(var permutation in allUniquePermutations){ log(permutation.ToArray()); Console.WriteLine(); } } } }
run
|
edit
|
history
|
help
0
FromBase64String
linq jean by Fausto
3
JAVA HELLO
Code Challenege
olution to problem #2 from projecteuler.net
The Code Garage
JOE'S C# CODE
Fórum GroupBy ➡ Sum & Aggregate customers' names
form