Predict the number – challenge description
Sequence 011212201220200112 … constructed as follows: first is 0, then repeated the following action: already written part is attributed to the right with replacement 0 to 1, 1 to 2, 2 to 0. E.g.
0 -> 01 -> 0112 -> 01121220 -> …
Create an algorithm that determines what number is on the N-th position in the sequence.
Input sample
Your program should accept as its first argument a path to a filename. Each line in this file contains an integer N such as 0 <= N <= 3000000000. Example:
0
5
101
25684
Output sample
Print out the number which is on the N-th position in the sequence. Example:
0
2
1
0