https://discuss.leetcode.com/topic/59478/google-onsite-array-elements-subtraction-game
irb(main):005:0> def numbers(a) (0..a.max).step(a[0].gcd(a[1])).to_a[1..-1] end
public Iterable<Integer> getReachableNums(int[] arr){
List<Integer> res = new ArrayList<Integer>();
assert(arr.length == 2);
int gcd = gcd(arr[0], arr[1]);
int max = Math.max(arr[0], arr[1]);
for (int i = 1; i*gcd <= max; i++){
res.add(i*gcd);
}
return res;
}
private int gcd(int a, int b){
if (a * b == 0){
return 1;
} else if (a == b){
return a;
} else {
a = (a < b) ? a : a + b;
b = (b > a) ? b : a - b;
a = (a > b) ? a - b : a;
return gcd(a, b - a);
}
}