Suppose you get a short input of increasing integers, say, "2 4", can you figure out what integers come after 4? If you assume the second integer is +2 greater than the first, then the next integer should be 6; but if you assume the second integer is double the first integer, then perhaps the next integer is 8. However, if the short input was "2 4 8", then you can almost be sure that the next integer is 16.
In short, the more numbers you get, the more hypotheses you can eliminate. We would like you to write a program, in Javascript. Please clearly indicate which one you would like to use. The program takes in a short list of increasing integers as inputs, hypothesize possible patterns in the integers, and generate the next 10 integers in line.
For instance, if the program receives the following input: 4 14
The program may assume that the next integer is the previous integer plus 10, thus it will generate:
24 34 44 54 64 74 84 94 104 114
but if the program receives the following input instead:
4 14 34
then it may hypothesize that the next integer is the previous multiplied by 2 plus 6.
74 154 3314 634 1274 2554 5114 10234 20474 40954
This is an open-ended problem that we're presenting, in other words, the input list of integers may have very interesting properties (e.g. a fibonacci sequence), there is no particular set of integer sequences that we are testing. So, be creative! try to identify as many sequences as you can think of.
This is what I would do:
N)0as the next numberN-order polynomial that goes through all the integersSo for your example of
The answer is
Which is clearly a logical relation, since it follows this equation perfectly:
(-7/3.)*i**3 + 8*i**2 + (-11/3.)*i + 2Where
iis in the index in the sequence. I found this with python/numpy:x = array([0, 1, 2, 3]) y = array([2, 4, 8, 0]) polyfit(x, y, deg=3)They might say this is not a real relation and ask for more numbers, so you might want to play it safe and use
N+10with all zeros. So:-0.000700 * i**9 + 0.030010 * i**8 + -0.545073 * i**7 + 5.452083 * i**6 + -32.632755 * i**5 + 118.526042 * i**4 + -251.163536 * i**3 + 275.991865 * i**2 + -113.657937 * i + 2.000000 2 4 8 0 0 0 0 0 0 0Advantages of this approach: