Monday, 27 April 2020

Strange Counter

After some observation by writing down a few cases, it becomes clear that
1 + 3(2n - 1) <= t
if we find n such that

n = floor(log2( (t - 1)/3 + 1 ))

1 + 3(2n - 1) is the cumulative time till latest counter.

then c = 3(2n - 1) gives us the value from which the latest counter will start counting (check this for a few cases to make it clear)

find the difference between the current time and 1 + 3(2n - 1). (to know how many steps to count down)
Subtract that difference from c and that is the answer

No comments:

Post a Comment