0

I am new to C++, and I need to write a code that can find a binary code by checking a bitset against inputs and excluding unnecessary options.

Example:

input-000000000 = 6 correct

This implies that there must be 3 ones present.

I need the code to only use strings that contain 6 zeros and three ones and print one attempting to narrow down the code.

Example:

000000111 = 5 correct

This must mean that two of those ones are correct and one must be a zero with a one somewhere in the first six digits.

How do I approach this problem?

I have so far the function:

string index2code (int i)
{
    return bitset <9>(i).to_string();
}

But I am still struggling to think of the logic, and how to use it.

peterh
  • 11,875
  • 18
  • 85
  • 108
Zeus _
  • 1
  • 2
  • 2
    Can you please detail your problem more clearly. How does `000000000` mean you have 6 correct and so you must have 3 ones? – NathanOliver Jan 13 '17 at 17:39
  • Search for "bulls and cows" on google or stackoverflow. – molbdnilo Jan 13 '17 at 17:53
  • the 9 zeros are compared against the code its trying to find. if the code is 010000011 then six digits are correct (the zeros). then the difference from six to the end of the code must be the amount of ones in the code. – Zeus _ Jan 13 '17 at 18:01
  • i have looked for bulls and cows repeatedly for days in many forms but am yet to find anything remotely useful in this case. i will keep searching in the meantime though – Zeus _ Jan 13 '17 at 18:04
  • why `000000111` is `5` not `7` correct? – apple apple Jan 13 '17 at 18:17
  • youre right. its 7. this problem is pulling me apart and i cannot find anything useful that helps. any advice/links/suggestions? – Zeus _ Jan 14 '17 at 14:21

0 Answers0