Skip to content

Instantly share code, notes, and snippets.

@puffin
Created February 15, 2017 14:11
Show Gist options
  • Save puffin/38aeece3476f247ae72f4e7cb8505f60 to your computer and use it in GitHub Desktop.
Save puffin/38aeece3476f247ae72f4e7cb8505f60 to your computer and use it in GitHub Desktop.
Predict the number

CHALLENGE DESCRIPTION:

The sequence "011212201220200112 ..." is constructed as follows:

first goes 0, and then the following action is repeated: existing part is added to the right, but 0 is replaced with 1, 1 with 2, and 2 with 0.

0 -> 01 -> 0112 -> 01121220 -> ...

Write an algorithm that determines what number is on the N-th position in the sequence.

INPUT SAMPLE:

Your program should accept a path to a filename as its first argument. Each line in the file contains a number N.

For example:

0
5
101
25684

OUTPUT SAMPLE:

Print out a number that is on the N-th position in the sequence.

0
2
1
0

CONSTRAINTS:

  1. 0 <= N <= 3000000000.
@sayedamayesha
Copy link

Could you please provide the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment