My problem is this:
Certain type of pump, requires a detonator to activate. These pumps are made in such a way that only their detonator can activate them. This is done by having the detonator and the plug of this one different for each pump.
You have in your possession 20 bombs with their 20 respective detonators. However, you do not know which detonator corresponds to which pump and you need to know. You can not compare any detonator with any pump, since for this you would need to plug them in and activate the pump. You can only compare the detonators to each other, and the bombs to each other.
Take into account that in the locations of the 1
to the 20
are the sizes of the plugs of the pumps and of the 21
to the 40
, the sizes of the detonators.
I have already solved it in the following way (recursively):
public class DetonadorAndBomb {
public static void bomb(int []a,int m,int n){
if(a[m]==a[n+1]){
System.out.println(a[n+1]);
if(!(m==(n+1))){
n=1;
bomb(a,m+1,n);
}
} else{
bomb(a,m,n+1);
}
}
public static void main(String[] args) {
int num[] = {1,3,3,1};
bomb(num,0,1);
}
}
And in the console it turns out:
1
3
3
It is assumed that you should not print the last value.