Thanks for the answer. I am looking for non-modules solution. I don't want to find all the solution. I just want to find next number in sequence. We should be able to derive from current number. Foe example : ( swap till you hit the largest number as first. If you hit the largest number as first, get the next number on left side and then place remaining number in sorted order ) : 117 => 171 => 711 or : 1234 =>(swap) 12.43 =>(largest 4) : 13.24 =>(swap) 13.42 => (largest) 14.23 =>(swap) :14.32 etc..