Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace StringPermute
- {
- static class Program
- {
- static void Main()
- {
- var word = "abc";
- foreach (var s in Permuta(string.Empty, word.ToArray()).Distinct())
- Console.WriteLine(s);
- }
- private static IEnumerable<string> Permuta(string a, char[] b)
- {
- if (b.Length == 0)
- yield return a;
- for (var i = 0; i < b.Length; i++)
- {
- foreach (var s in Permuta(a + b[i], b.Where((c, j) => j != i).ToArray()))
- yield return s;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement