Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
public class FindMissingPermutation
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String[] givenPermutations = { "ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD",
|
||||
"ADCB", "CDAB", "DABC", "BCAD", "CADB", "CDBA",
|
||||
"CBAD", "ABDC", "ADBC", "BDCA", "DCBA", "BACD",
|
||||
"BADC", "BDAC", "CBDA", "DBCA", "DCAB" };
|
||||
String characterSet = givenPermutations[0];
|
||||
// Compute n! * (n - 1) / 2
|
||||
int maxCode = characterSet.length() - 1;
|
||||
for (int i = characterSet.length(); i >= 3; i--)
|
||||
maxCode *= i;
|
||||
StringBuilder missingPermutation = new StringBuilder();
|
||||
for (int i = 0; i < characterSet.length(); i++)
|
||||
{
|
||||
int code = 0;
|
||||
for (String permutation : givenPermutations)
|
||||
code += characterSet.indexOf(permutation.charAt(i));
|
||||
missingPermutation.append(characterSet.charAt(maxCode - code));
|
||||
}
|
||||
System.out.println("Missing permutation: " + missingPermutation.toString());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue