Note: You have to calculate the numbers in both arrays. Finding numbers that fit by random isn't easy but still possible.
The arrays (idx and cutter) contain wrong numbers in the challenge, so you have to find the correct values mathematically.
import java.math.BigInteger;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Challenge {
public static int divisor = 0;
public static int[] menge = {1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000};
public static void main(String[] args) {
int[][] arrays = calculateArrays();
int[] idx = arrays[0];
int[] cutter = arrays[1];
if (cutter[cutter.length - 1] == idx.length)
start(idx, cutter);
}
private static int[][] calculateArrays() {
int[][] arr = new int[2][];
arr[0] = new int[]{1, 22, 23, 12, 11, 11, 5, 9, 11, 13, 12, 13, 15};
arr[1] = new int[]{1, 4, 13};
return arr;
}
private static void start(int[] idx, int[] cutter) {
int[] finalIdx = idx;
int[] nums = IntStream.range(0, idx.length).boxed().mapToInt(i -> menge[finalIdx[Integer.parseInt(i.toString())]]).toArray();
divisor = nums.length;
int[][] groups = new int[cutter.length][];
for (int i = 0; i < cutter.length; i++) {
int from = i == 0 ? 0 : cutter[i - 1];
int to = cutter[i];
groups[i] = Arrays.copyOfRange(nums, from, to);
}
String num1 = "", num2 = "", num3 = "", num4 = "", num5 = "", num6 = "", num7 = "", num8 = "", num9 = "";
int tmpLength = 0, tmpReduce = 0, tmpSerial = 0;
for (int i = 0; i < cutter.length; i++) {
int[] group = groups[i];
num1 += (i + 1) + "" + group.length;
tmpLength += group.length;
num2 += (i + 1) + "" + tmpLength;
num3 += (i + 1) + "" + Arrays.stream(group).reduce(0, (subtotal, element) -> subtotal + element);
tmpReduce += Arrays.stream(group).reduce(0, (subtotal, element) -> subtotal + element);
num4 += (i + 1) + "" + tmpReduce;
num5 += (i + 1) + "" + Arrays.stream(group).mapToObj(x -> x + "").collect(Collectors.joining());
num6 += (i + 1) + "";
for (int j = 0; j < group.length; j++) {
tmpSerial += group[j];
num6 += tmpSerial + "";
}
num7 += (i + 1) + "" + (group.length + Arrays.stream(group).reduce(0, (subtotal, element) -> subtotal + element));
num8 += (i + 1) + "" + (group[0] + group[group.length- 1]);
int[] sorted = Arrays.stream(group).boxed().mapToInt(n -> Integer.parseInt(n.toString())).sorted().toArray();
num9 += (i + 1) + "" + (sorted[0] + sorted[sorted.length- 1]);
}
checkArgs(nums, groups, new String[]{num1, num2, num3, num4, num5, num6, num7, num8, num9});
}
private static void checkArgs(int[] nums, int[][] groups, String[] args) {
boolean isOK = true;
if (groups.length < 3 || divisor < 13) {
isOK = false;
}
BigInteger bDivisor = new BigInteger(divisor + "");
BigInteger b0 = new BigInteger("0");
for (int i = 0; i < args.length; i++) {
BigInteger bi = new BigInteger(args[i]);
if (!bi.mod(bDivisor).equals(b0)) {
isOK = false;
break;
}
}
if (isOK == true) {
System.out.println("The selected numbers are valid. " + Arrays.toString(nums));
}
}
}