#C++ Allergies problem

9 messages · Page 1 of 1 (latest)

young vine
#

I am trying to finish the problem from several hours but now these test cases are burning me out.
cannot understand the problem statement clearly and also test cases are also unable to be understood now.
if allergy score is 3, then person allergic to eggs is true but if 5 score then person not allergic to peanuts. how so. isn't that the same logic.
what I can understand from eggs and 3 score is that if score is greater than allergy score and there is no other score in the list that matches the given score then it is true.
please someone help me with this. Much helpful

lunar orchid
#

Are you familiar with how binary notation works?

zinc plinth
#

There's only one way to reach a value of 5 by only summing powers of 2 (1, 2, 4, 8...) without repeating the same number: 1 + 4. As peanuts is associated with 2, the person can't be allergic to peanuts (because 2 is not used to reach the sum of 5, only 1 (eggs) and 4(shellfish)).

This exercise is all about how to think in binary numbers.

young vine
#

Alright thanks for the idea. I 'll try to learn and solve using binary way. (bitwise operators I guess you are talking about)

lunar orchid
#

Written in binary, 3 is 011. 5 is 101.

#

The middle digit corresponds to peanuts. 3 has a 1 and 5 does not in that digit.

#

This exercise is generally solved using bitwise operators but they aren't strictly needed.

young vine
#

Got the idea. thanks Isaac

zinc plinth
#

all integers can be represented in any base, we usually use only base 10 (decimal numbers). Decimal numbers have 10 possible digits, from 0 to 9, and the position of each digit indicates the power of 10 associated with it.

So, for instance, 45 is 4 * 10^1 + 5*10^0 = 40 + 5.

Binary numbers are numbers in base 2 which have only 2 possible digits, 0 and 1. Similarly, the position of each digit indicates the power of 2 associated with it.

Every number can only be represented in one single way for any given base