По просьбе _nightwing - гадалка Шеннона

Apr 27, 2005 22:52

#include

// MEMORY must be an integer between 1 and 7. Value below is approximately optimal.
// Increasing it takes effect in better guessing quality, but longer tuning at start of guessing.
#define MEMORY 4

// SKLEROZ must be a double between 0 and 1 (excluding both 0 and 1). Value below is approximately optimal.
// Increasing it takes effect in better adaptation during long-term guessing, but lead to worse adaptation to short-term variations (e.g. changes of guessing person(s))
#define SKLEROZ 0.999

// QUALITY must be a double greater than 1. Value below is approximately optimal.
// Increasing it takes effect in more guaranteed guessing when guessed, but more often declines to guess.
#define QUALITY 1.5

int main()
{
double history[MEMORY];
int t=0, g=0, r;
for (unsigned char c=0; c != MEMORY; c++)
history[c]=0;
c=0;
printf("I am an electronic prognosist.\nMy algorythm was created by K. Shennon.\n"
"Now I tell You in short about my work...\n\n"
"You will write on a paper a binary number: 0 or 1\n"
"I'll try to guess a number has been written\n"
"And You will have to say if I really guess Your number\n"
"But maybe I can't guess Your number\n"
"In this case please tell me number You've wrote\n"
"Let's go!!!\n");
loop:
c<<=1;
c&=( ( ~0 )<<( MEMORY ) );
if (history[c+1]>QUALITY*history[c])
{
printf("I think You've guessed 1. And what was really guessed?");
scanf("%u",&r);
if (!(r-1))
g++;
};
if (history[c]>QUALITY*history[c+1])
{
printf("I think You've guessed 0. And what was really guessed?");
scanf("%u",&r);
if (!r)
g++;
};
if ((history[c+1]
Previous post Next post
Up