I will show you an example having 5-bits which eventually generalizes to n-bits.
You start asking with all 0's as 00000. If friend answers 5, well you guessed it correct!
If answer is 0, invert each bit and get the guess correct.
If answer is between 1 to 4 some work needs to be done, but don't worry it takes less than 5 questions :)
Guess | Response |
00000 | 1 |
10000 | 0 (All places incorrect) |
01111 | Hurray! |
10000 | 2 (1st place correct) |
11000 | 1 (2nd place incorrect) |
10100 | 3 (1,2,3 are correct) |
10111 | Hurray! |
11000 | 3 (2nd place correct) |
11100 | 2 (3rd place incorrect) |
11011 | Hurray! |
Hence using this repetitive technique solution can be found under 5 or even n questions.
Your friend thinks of an n-bit string (some sequence of 0's and 1's such as 01011...
Problem 3. A ternary string is a sequence of O's, 1's and 2's. Just like a bit string, but with three symbols 0,1 and 2. Let's call a ternary string good provided it never contains a 2 followed immediately by a 0, i.e., does not contain the substring 20. Let Go be the number of good strings of length n. For example, G_1=3, and G. = 8 (since of the 9 ternary strings of length 2, only one is not...
2. A binary string is a finite sequence u-діаг . . . an, where each ai is either 0 or 1. In this case n is the length of the string v. The strings ai, aia2,... ,ai... an-1,ai... an are all prefixes of v. On the set X of all binary strings consider the relations Ri and R2 defined as follows: Ri-(w, v) w and v have the same length ) R2 = {(u, v) I w is a prefix...
2. A binary string s a finite sequence u = ala2 . . . an, where each ai įs either 0 or 1. In this case n is the length of the string v. The strings ai,aia2,...,ai...an-1,aan are all prefixes of v. On the set X of all binary strings consider the relations Ri and R2 defined as follows R, = {(u, u) | w and u have the same length } {(w, u) | w is a prefix of...
2. A binary string is a finite sequence v = a1a2 . . . an, where each ai is either 0 or 1. In this case n is the length of the string v. The strings a1, a1a2, . . . , a1 . . . an−1, a1 . . . an are all prefixes of v. On the set X of all binary strings consider the relations R1 and R2 defined as follows: R1 = {(w, v) | w...
3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa Give a leftmost derivation for the string. 3 points) (4 poiots) (5 points) (3 points) sECTION IWOLAttcmpt.any 3.(or 2) questions from this.scction Suppose we have two tokens: (1) the keyword if, and (2) id-entifiers, which are strings of letters other than if. Show the DFA for these tokens. Give a nightmost derivation for the string. Give a parse tree for the string i) Is...
#include <iostream> //write preprocessor file for string datatype here using namespace std; //write your function prototypes here: int main() { cout << "Welcome to Mad Lib.\n\n"; cout << "Answer the following questions to help create a new story.\n"; string name = askText("Please enter a name: "); string noun = askText("Please enter a plural noun: "); int number = askNumber("Please enter a number: "); string bodyPart = askText("Please enter a body part: "); string...
1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash is quite common in many Bloom Filters, the hashing algorithm to be implemented is a mix of the the following algorithmic models, specifically, a multiply & rotate hash colloquially known as a murmur hash, and an AND, rolale, & XOR hash colloquially known as an ARX hash. 2 Requirements • Inputs. Read the input file which contains strings...
Some java questions: 18. Consider the following class definitions public class TestAB public static void main (String args) A bl new B() в ь2 -new B() ; b1.х, А.у, Ь2.х, в.у); System.out.printf ("%d, Sd, %d, d\n", class A public int x = 2; public static int y = 4; public A () ( X=y- class Bextends A public int x = 32; public static int y = 45; public B ( x ++y What is the result of attempting to...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...
please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...