This section is for those interested in the way it works
Here are the codes to figure out which combination of enhancements to achieve the accuracy/alacrity combination is right for you. This is to be used with Gear: iLvL 306 by Adu, Smarty & advieser
If you would like to test it or edit to find out a specific combination number, first you need to head on over to CodeChef and change the IDE to JAVA. Select all and then paste the following code below then run it to get the output.
Gear Sum
import java.util.*;
class GearSum {
static void sum_up_recursive(ArrayList<Integer> numbers, int target, ArrayList<Integer> partial, Set<ArrayList<Integer>> resultSet) {
int s = 0;
for (int x: partial) {
s += x;
}
if (s == target) {
// Deduplication of results
Collections.sort(partial);
resultSet.add(partial);
}
if (s >= target) {
return;
}
for (int i = 0; i < numbers.size(); i++) {
int n = numbers.get(i);
ArrayList<Integer> partial_rec = new ArrayList<>(partial);
partial_rec.add(n);
sum_up_recursive(numbers, target, partial_rec, resultSet);
}
}
static void sum_up(ArrayList<Integer> numbers, int target) {
final Set<ArrayList<Integer>> resultSet = new HashSet<>();
sum_up_recursive(numbers, target, new ArrayList<>(), resultSet);
for (ArrayList<Integer> result : resultSet) {
System.out.println("sum("+Arrays.toString(result.toArray())+")="+target);
}
}
public static void main(String args[]) {
Integer[] numbers = {431, 431, 429, 427, 424, 422, 420, 418, 416, 414, 412,
409, 407, 405, 403, 401, 398, 396, 394, 392, 389, 409, 347, 347, 344, 344, 342, 342,
339, 342, 344, 347, 349, 352, 354, 357, 359, 361, 364, 364, 364, 364, 431, 451, 449, 447,
445, 443, 441, 439, 437, 435, 433, 431, 429, 427, 424, 422, 420, 418, 416, 414, 412, 108};
Scanner input = new Scanner(System.in);
System.out.print("Target Number: ");
int intTarget;
intTarget = input.nextInt();
int target = intTarget;
sum_up(new ArrayList<>(Arrays.asList(numbers)),target);
}
}
Code goes by recursion and therefore output can show duplicates. The code is messy but it gets the job done, if you'd like to edit and clean it up be my guest! I also gave out raw codes for those that don't have an IDE and want to know how it works.
Might update code to actually show mod along with the numbers. Stay tuned.