@dukeforever You can get to know the digits in the number by comparing it with 1111, 2222, 3333, 4444, 5555. Then you know that the number is a permutation of these digits.

In worst case, u can try all the 4! permutations of these digits.

If you want to improve upon his, try looking into the following facts:

Try all rotations of a permutation, record the results.

Note here, sum of results should be 4.

The results will either be a permutation of either {0, 0, 0, 4} or {1, 1, 2, 0}

In the first case, you already know the result.

In the second case, you have 4*2 candidates. You can try all.

So, with this approach, worst case tries will be 5 + 4 + 4*2 = 17.