samedi 1 avril 2017

Guess binary number

With the input:
N C
6 L
101101
attempt

My code has to find out the correct binary number (which can have up to 1000 characters - only even numbers) in less than 2050 attempts/guesses, and it does, but only in the easy mode where in each attempt/guess it returns the amount of wrong numbers.

Now the issue is in the hard mode where it returns: 0 if it's correct; N/2 if it's exactly half correct (not more, not less); N in any other situation.

N is the number of characters in the binary number.
L/C is just easy/hard mode.

My code:

#include "valuer.c"
#include "valuer.h"

void solve(int N, char C)
{
  char attempt[MAXN];
  int i, wrong;

  for (i = 0; i < N; i++)
    attempt[i] = '0';

  wrong = guess(attempt);
  for (i = 0; i < N; i++)
  {
    attempt[i] = '1';
    if (wrong <= guess(attempt))
      attempt[i] = '0';
    else
      wrong--;
  }
}

How it finds the number in easy mode:

0|101101|0
-|------|-
1|000000|4
2|100000|3
3|110000|4
4|101000|2
5|101100|1
6|101110|2
7|101101|0

My plan to get it in hard mode is somehow randomly get to half way and then test 1 by 1 or maybe 2 by 2 characters in the second half of the binary number and see it changes from N/2 to N and then reverte the number so it's not like 60% correct until I get to the end where I have the correct numbers saved and apply them all.




Aucun commentaire:

Enregistrer un commentaire