create candidates method

This commit is contained in:
Krystian Madra 2018-06-28 00:34:39 +02:00
parent 8bc941ab4e
commit 935fba7d15

View File

@ -136,9 +136,9 @@ public class Main {
}
public static LinkedList<Integer> substractPolynomials(LinkedList<Integer> p1, LinkedList<Integer> p2){
public static LinkedList<Integer> substractPolynomials(LinkedList<Integer> p1, LinkedList<Integer> p2){
LinkedList<Integer> result = new LinkedList<Integer>();
LinkedList<Integer> result = new LinkedList<Integer>();
LinkedList<Integer> p2Copy = new LinkedList<Integer>();
@ -163,5 +163,42 @@ public class Main {
return result;
}
public static LinkedList<LinkedList<Integer>> createCandidates(LinkedList<Integer> orig, int mod){
LinkedList<LinkedList<Integer>> elements = new LinkedList<LinkedList<Integer>>();
LinkedList<Integer> result = new LinkedList<>();
result.add(0);
int i = 0;
while (result.size() < orig.size()){
elements.add(new LinkedList<>(result));
i = (i + 1) % mod;
result.set(0, i);
if (i == 0){
if (result.size() == 1){
result.add(1);
}else {
int tmp = (result.get(1) + 1);
result.set(1, tmp);
for (int k = 1; k < result.size(); ++k){
if (result.get(k) == 0 || result.get(k) % mod != 0) break;
tmp = (result.get(k)) % mod;
result.set(k, 0);
if (tmp == 0){
if (k + 1 < result.size()){
tmp = (result.get(k + 1) + 1);
result.set(k + 1, tmp);
} else {
result.add(1);
}
}
}
}
}
}
return elements;
}
}