You've taken a lot of 'IQ'-style tests, and noticed a common pattern appearing among them. They ask you to continue a given sequence of numbers. Say you're given the numbers 1,2,3,4,5, and are asked: what's the next number? Of course, the answer is 6. A slightly more complicated sequence would be 3,6,12,24,48, where 96 is the answer. Or, if the test is really tough, it might be even 1,4,13,40, where 121 is an answer (the latter follows the rule "multiply by 3 and add 1").
You've decided to write an automatic solver for these problems. It will be based on the following proposition: the rule for generating the sequence is always "multiply by a and add b", where a and b are integer (not necessarily positive) numbers.
You are given a int[] **previous** containing the first several numbers of the sequence. If this sequence could not be constructed using the above rule, return "`BUG`". If it could, and you can uniquely determine the next number, return a string containing that number without spaces or extra leading zeroes. If there are several possible next numbers, return "`AMBIGUITY`" (quotes for clarity only). |