Hello everyone!
Lets imagine that we have a vector full of numbers:
1 2 3 4 5 6
|
vector<double> nums
nums.push_pack( 0.5 );
nums.push_pack( -0.3 );
nums.push_pack( 0.9 );
nums.push_pack( 0.01 );
nums.push_pack( -0.75 );
|
Totally random numbers between -1.0 - 1.0
Now instead of making a function, we will make a class instead.
Each vector has its own class.
1 2 3 4 5
|
class guess_avarage
{
public:
double guess( double in ) { return 0.0; }
}
|
Having class allows us to have variables to help us guess it better.
This is how i would feed the function:
1 2 3
|
while(1) {
for( int a = 0; a < nums.size(); a++ ) guess_avarage.guess( nums[a] );
}
|
I put there a while loop to show you that patern will repeat.
Now our function should return the avarage of the numbers inside the nums vector. There is a catch.
The numbers inside the nums vector are always changing.
We can't control how they are changing but the closer the numbers get to 0
the better our returned avarage was.
That means if we will do well with guessing avarage then all numbers, inside the vector, will turn into 0 eventually.
The numbers can always only be between -1.0 - 1.0 no matter how bad we're doing but -1.0 and 1.0 is the worse.
The closer our returned value to 0 is, the less the numbers may change, inside the vector.
Also one other thing is that sometimes the new numbers may appear in vector or some may go away.
Number can pop in or away between one pattern meaning that sometimes
we can't even finish the pattern without having a new number in it or a one number less. But the pattern will repeat itself often.
Now the rules are that we can not see what is inside the nums vector.
We don't know what was the previous number or what will be the next number however we can create a variable inside the class for previous num value.
We can have pretty much anything inside the class but
doing something like adding a vector to a class and checking if pattern repeats
its a bad idea cause that vector will grow too large and i will run out of memory fast.
The goal is to guess the number what is close to actual current avarage.
Any solution to my problem?
Thanks you!