Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ParallelTest {
- class Program {
- static IEnumerable<string> AllCombinationsNoRepeat(string prefix, int length) {
- return
- length == 0
- ? new[] { prefix }
- : new[] { prefix }.Concat(
- Enumerable.Range(0, 9)
- //.AsParallel() //FIXME: Se debe quedar deadlocked esperando un worker thread libre...
- .Select(n => prefix+n) //Append char
- .Where(s => s.GroupBy(ch=>ch).All(g=>g.Take(2).Count() < 2)) //No chars repeated
- .SelectMany(s => AllCombinationsNoRepeat(s, length-1)) //Combine recursively
- )
- ;
- }
- static void Main(string[] args) {
- foreach(var x in AllCombinationsNoRepeat("", 9))
- Console.WriteLine(x);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment