# Repeat before Zero

## Repeat before Zero

My original intuition about the "repeat original values" aspect of this problem is that it served as a safety net in case the bytes never reach zero simultaneously. When the original values repeat, it starts over and the same sequence of numbers would be generated the second time around, once again missing zero.

Wrong! Here's a simple counter-example that one can hand simulate for better understanding:

./running 000000000000000000000000ffffff00 00000000000000000000000000000001 00000000000000000000000000000001

It repeats the input on cycles 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560 and 2816. Then on cycle 3072 it reaches all zeros for the first time. (The correct solution on this input would be 256.)

The moral: If you find a zero, don't report it as the solution until you're sure that the bytes do not repeat their initial state on an earlier cycle.

- Rick

4 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

While I agree with you that 256 should be the answer here let me play devils advocate, the problem description says :

"The goal of your code is to compute the number of cycles required to
reach all zero values simultaneously or detect the repetition of the
original input values."

Nowhere does that say 'the lowest' or 'the first' so 2304 would just as valid as an answer as 3072

Intel should probably clarify this. Will 'any' solution do? or does it have to be the lowest? or do we have to report 'all' solutions? If 'any' solution it allowed what is stopping us from doing a printf("158913789952\n"); and calling it a day?

I'm sure that need find minimal number of cycles, becouse otherwise I can always print 158913789952 (2^32*37) and that will be true answer.

Hi,
In the problem statement, we have described that your code should find the number of cycles required to reach all zero values or repeat the original input values. So, you should report whichever is earlier.

Hope this clarifies.
Thanks
-Rama