Strange Counter
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Sample case — your program reads stdin and prints to stdout.
Strange counter: starts at 3 at time 1, decrements each second. When it reaches 1, resets to 2×previous start value. Find value at time t.
Pattern: Cycle 1: times 1-3, values 3,2,1. Cycle 2: times 4-9, values 6,5,4,3,2,1. Cycle 3: times 10-21, values 12,11,...,1. For time t, find which cycle and calculate value.
Example: t=4 → Cycle 2, position 1 → Value = 6 - (4-4) = 6
Input format
A single integer t.
Output format
The counter value at time t.
Constraints
1 ≤ t ≤ 10¹²