Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class FindMissingPermutation {
|
||||
public static void main(String[] args) {
|
||||
Joiner joiner = Joiner.on("").skipNulls();
|
||||
ImmutableSet<String> s = ImmutableSet.of("ABCD", "CABD", "ACDB",
|
||||
"DACB", "BCDA", "ACBD", "ADCB", "CDAB", "DABC", "BCAD", "CADB",
|
||||
"CDBA", "CBAD", "ABDC", "ADBC", "BDCA", "DCBA", "BACD", "BADC",
|
||||
"BDAC", "CBDA", "DBCA", "DCAB");
|
||||
|
||||
for (ArrayList<Character> cs : Utils.Permutations(Lists.newArrayList(
|
||||
'A', 'B', 'C', 'D')))
|
||||
if (!s.contains(joiner.join(cs)))
|
||||
System.out.println(joiner.join(cs));
|
||||
}
|
||||
}
|
||||
|
|
@ -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