CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* NEXT NUMBER PREDICTOR
*
*
* created by AZTECCO 3/2018
*
* Find the next number out of a sequence.
*
* NOTE: polynomial interpolation.
*
*/
#include <iostream>
#include <vector>
int predict( std::vector<int>& input )
{
std::vector<int> x;
for ( std::size_t i = 0 ; i < input.size() - 1 ; ++i )
x.push_back( input[ i + 1 ] - input[ i ] );
int f = x[ 1 ] / x[ 0 ];
int a = x[ 1 ] % x[ 0 ];
int step = x.back() * f + a ;
if ( a != 0 )
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run