Ad

Write a function which would take two figures as a parameters and generate List of numbers which would contains figures from 1 fo n (n - first input) and lenght of each number should be equals to n .

Then return number at m position ( m - second input).
If number at that position doesn't exist return -1;

Examples :

Generator(2 ,3) => 11 12 21 22

should return 21

Generator(3, 10) => 111 112 113 121 122 123 131 132 133 211 212 213 221 222 223 231 232 233 311 312 313 321 322 323 331 332 333

should return 211

Good luck :)

using System;
using System.Linq;
using System.Collections.Generic;


public class NumbersFinder
{
    public static int Generator(int size , int position){
        if ( Math.Pow( size , size ) < position )
            return -1;
        List<string>  arr = new List<string>();
        for (int i = 0; i < size; ++i)
            arr.Add((i+1).ToString());
        List<string>  newArr;
        while (arr.Count != Math.Pow(size,size)){
            newArr = new List<string>();
            for (int j = 0; j < arr.Count; j++)
                for (int i = 0; i < size; i++)
                    newArr.Add(arr[j]+(i+1));
            arr.Clear();
            arr.AddRange(newArr);
        }
        return Convert.ToInt32(arr[position - 1]);
    }
}