Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That taks turned to be awesome on so many levels. I present you a pure LINQ (but not very efficient) solution.</p> <pre><code> static class Program { static void Main(string[] args) { var res = "cat".Anagrams(); foreach (var anagram in res) Console.WriteLine(anagram.MergeToStr()); } static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; Anagrams&lt;T&gt;(this IEnumerable&lt;T&gt; collection) where T: IComparable&lt;T&gt; { var total = collection.Count(); // provided str "cat" get all subsets c, a, ca, at, etc (really nonefficient) var subsets = collection.Permutations() .SelectMany(c =&gt; Enumerable.Range(1, total).Select(i =&gt; c.Take(i))) .Distinct(new CollectionComparer&lt;T&gt;()); return subsets; } public static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; Permutations&lt;T&gt;(this IEnumerable&lt;T&gt; collection) { return collection.Count() &gt; 1 ? from ch in collection let set = new[] { ch } from permutation in collection.Except(set).Permutations() select set.Union(permutation) : new[] { collection }; } public static string MergeToStr(this IEnumerable&lt;char&gt; chars) { return new string(chars.ToArray()); } }// class // cause Distinct implementation is shit public class CollectionComparer&lt;T&gt; : IEqualityComparer&lt;IEnumerable&lt;T&gt;&gt; where T: IComparable&lt;T&gt; { Dictionary&lt;IEnumerable&lt;T&gt;, int&gt; dict = new Dictionary&lt;IEnumerable&lt;T&gt;, int&gt;(); public bool Equals(IEnumerable&lt;T&gt; x, IEnumerable&lt;T&gt; y) { if (x.Count() != y.Count()) return false; return x.Zip(y, (xi, yi) =&gt; xi.Equals(yi)).All(compareResult =&gt; compareResult); } public int GetHashCode(IEnumerable&lt;T&gt; obj) { var inDict = dict.Keys.FirstOrDefault(k =&gt; Equals(k, obj)); if (inDict != null) return dict[inDict]; else { int n = dict.Count; dict[obj] = n; return n; } } }// class </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload