Send your feedback or ask for help here!
I had to reread myself a few times
I’m not quite convinced of the definition in the puzzle.
In the given example, why (x != 5) is not overshadowed by condition (x > 4) ???
‘Visualise’ it this way:
if (x > 4) console.log('x > 4'); else if (x == 9) console.log('x == 9'); else if (x < 4) console.log('x < 4'); else if (x != 5) console.log('x != 5'); else if (x < 6) console.log('x < 6');
Code for condition x != 5 can be reached if x = 4;
The statement said,
Condition (x == 9) is overshadowed by condition (x > 4).
Condition (x < 6) is overshadowed by conditions (x > 4) and (x != 5).
For these two reasons, it gives the answer as 1 4
because (x == 9) is in index 1; (x < 6) is in index 4.
If x is 6, it will be handled by the (x > 4) condition, and will not go into the (x != 5) condition.
Are we finding a new overshadow case:
Condition (x != 5) is overshadowed by condition (x > 4) ?
Should the answer also include the index of (x != 5), which is 3?
Basically, after each condition, you want to update the union of (integer) intervals that still can be reached.
Write your intervals on paper and you’ll see that the testcases/validators are correct.
It’s too early to jump into implementation design at this stage.
Try to understand the problem by reading codes.
Yatech and the puzzle statement gave a very solid example code, and I added a randomly picked value for x;
When it runs, only “x > 4” is returned. If we remove the (x > 4) condition, “x != 5” will be returned. Why “x != 5” was hidden in the first place? Because it was under the shadow of an earlier condition.
Another approach. Try to understand the problem by reading text.
The statement defined overshadowing as
an overshadowed condition is a condition for which any values satisfying the condition also satisfy at least one previous condition, thus making the overshadowed block of code unreachable.
There is a value “x is 6” satisfying the condition (x != 5), and this x value is also satisfying one previous condition (x > 4), thus making the code under (x != 5) unreachable. By the statement definition, the previous condition is overshadowing the later condition.
I do not see any reason this is not overshadowing and not belonging to one of the answers.
The condition x != 5 is not overshadowed because at least one value exists for which the condition is fulfilled (x = 4).
Conditions x == 9 and x < 6 are overshadowed because they cannot be fulfilled for any x value.
It does not match the puzzle statement
any values satisfying the condition also satisfy at least one previous condition
If my English is good enough to interpret it correctly, “any value” means from all of the values true for the condition we try to find anything matching another condition.
So x=6 is one of the possible values to use. Equally we can use x=10 or x=100 or x=4.
For all these [6, 10, 100, 4] values, if we find any of them satisfying at least one previous conditions, e.g (x>4), this is enough evidence of overshadowing.
I think the key point is to look for those conditions where the code will never be reachable because ALL integers have satisfied one of the previous conditions, instead of focusing on individual integers.
I agree the wording in the statement may be confusing. Do you have any suggestions on how to improve it?
You gave an excellent keyword to describe the real requirement - “will never be reachable”
The puzzle is about finding “unreachable codes”.
“Overshadowing” can be misleading because “partial overshadowing” is also an overshadowing. Complete overshadowing is better to be described as unreachable codes.
Both unreachable codes and (partial) overshadowing add extra risks to conceal bugs.
What is “partial overshadowing”?
Using the same sample code given above, (x > 4) is partially overshadowing (x != 5) because some x values (like 6) that should have been true for (x!=5) will be captured by the preceding (x>4), but some x values (like 0) will still fall into the (x!=5) true condition.
OK, well explained.
I have left a comment in the contribution view of the puzzle and will wait and see whether the original author has any feedback.
[Edit: I have updated the statement as the original author has not any feedback for a few weeks.]
(x != 5) and ( x > 4) does not overshadow (x < 6), 'cause there isn’t any value in set of the intersection of (x != 5) and ( x > 4) that satisfy the condition (x < 6).
it might be intended to say x < 4? That’s what I’m thinking now. (Note: its referring to the example test case so that seems plausible.
I think there is a mistake in validator 15 and 16 : the interval of x is really bigger than in all the tests. It’s ok with conditions in the puzzle but doesn’t fit with the tests.
I don’t think that counts as a “mistake”. The constraints section clearly states that x is in (-(2 ^ 30), 2 ^ 30).