Last active
December 15, 2021 06:56
-
-
Save Agoxandr/54bdcecfcde1eb24efe5deb060d3471a to your computer and use it in GitHub Desktop.
Bestimmen Sie begründet die Anzahl der Permutationen von [6] mit höchstens drei Fixpunkten.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var unchaged = new int[] { 1, 2, 3, 4, 5, 6 }; | |
var perms = GetPermutations(unchaged, 6); | |
int counter = 0; | |
var tolerances = new int[] { 0, 0, 0, 0 }; | |
foreach (var perm in perms) | |
{ | |
var list = perm.ToList(); | |
var text = ""; | |
int tolerance = 0; | |
for (int i = 0; i < list.Count; i++) | |
{ | |
var item = list[i]; | |
if (item == unchaged[i]) | |
{ | |
if (tolerance < 4) | |
{ | |
tolerance++; | |
} | |
else | |
{ | |
text = ""; | |
break; | |
} | |
} | |
text += item + " "; | |
} | |
if (text != "") | |
{ | |
if (tolerance < 4) | |
{ | |
tolerances[tolerance]++; | |
counter++; | |
Console.WriteLine(text + "Fixed points " + tolerance); | |
} | |
} | |
} | |
Console.WriteLine(counter); | |
for (int i = 0; i < 4; i++) | |
{ | |
Console.WriteLine("Tolerance " + i + " " + tolerances[i]); | |
} | |
static IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> list, int length) | |
{ | |
if (length == 1) return list.Select(t => new T[] { t }); | |
return GetPermutations(list, length - 1).SelectMany(t => list.Where(o => !t.Contains(o)), (t1, t2) => t1.Concat(new T[] { t2 })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment