using System; using System.Collections.Generic; class Program { static void Main(string[] args) { var histogram = new Dictionary{{"ABC", 0}, {"ACB", 0}, {"BAC", 0}, {"BCA", 0}, {"CAB", 0}, {"CBA", 0}}; for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) for(int k =0; k < 3; k++) { var sc = new SwappableChars("ABC"); sc.Swap(0, i); sc.Swap(1, j); sc.Swap(2, k); histogram[sc.ToString()] += 1; } foreach (var x in histogram) Console.WriteLine("{0}: {1}", x.Key, x.Value); } } public class SwappableChars { private char[] mChars; public SwappableChars(string text) { mChars = text.ToCharArray(); } public void Swap(int i, int j) { var hoge = mChars[i]; mChars[i] = mChars[j]; mChars[j] = hoge; } public override string ToString() { return new string(mChars); } }