A. Garland
The problem asks us to turn on all four colored light bulbs in a garland, with the restriction that a bulb can only be switched if its color differs from the one switched previously. The goal is to find the minimum number of operations needed to turn all bulbs on, or determine if it’s impossible.
If u observe there are only Five possible configurations of the bulbs:
AAAA: All bulbs are of the same color. This makes it impossible to turn on all bulbs, as you cannot alternate between different colors.
Answer:-1
.AAAB: Three bulbs are of the same color, and one bulb is different. In this case, it's impossible to turn all bulbs on in just 4 moves because at least one bulb must be turned on, off, and on again, making the minimum number of operations 6.
Answer:6
.AABB: There are two pairs of bulbs with the same colors. In this configuration, you can alternate between the two pairs of bulbs and turn them all on in exactly 4 operations.
Answer:4
.AABC: Two bulbs share the same color, while the other two are different. Similarly, you can alternate between different-colored bulbs, and all bulbs can be turned on in 4 operations.
Answer:4
.ABCD: All four bulbs are of different colors. There are no restrictions in this case, and you can easily turn all bulbs on in 4 operations.
Answer:4
.
Summary
For the AAAA case, the answer is -1
.
For the AAAB case, the answer is always 6
.
For the AABB, AABC, and ABCD cases, the answer is 4
.
B. Detective Book
In this problem, Ivan is reading a detective book where each page introduces a mystery explained on a later page. The goal is to determine how many days it will take for him to read the entire book, given that he can only read a sequence of pages until all mysteries encountered are explained.
How does Ivan decide when to stop?
Ivan stops reading at the end of a day only when all the mysteries he has read so far are fully explained by that point.
Example Walkthrough:
Consider 9 1 3 3 6 7 6 8 8 9
The second line means: - Page 1 explains the mystery on page 1. - Page 2 introduces a mystery that gets explained on page 3. - Page 3 introduces a mystery that gets explained on page 3. - Page 4 introduces a mystery that gets explained on page 6. - And so on...
Day 1: - Ivan starts with page 1, which is explained by itself. He can stop here because there's no pending mystery. - So, Day 1 ends after page 1.
Day 2: - Ivan starts with page 2. Page 2 introduces a mystery explained by page 3. - He reads page 3, which also introduces a mystery explained by page 3 (already read). - Now all mysteries (from page 2 and 3) are explained, so he can stop here. - Day 2 ends after page 3.
Day 3: - Ivan starts reading from page 4. It introduces a mystery explained by page 6. - He reads pages 4, 5, 6, 7, and 8, because all these pages introduce mysteries that are explained only up to page 8. - After page 8, all mysteries are explained, so he can stop. - Day 3 ends after page 8.
Day 4: - Ivan reads page 9, which explains itself. There are no pending mysteries. - Day 4 ends after page 9.
Thus, the answer is 4 days.