Generate all cyclic permutations of a number | Function to count the total number of digits in a number . ; Function to generate all cyclic permutations of a number ; Following three lines generates a circular pirmutation of a number . ; If all the permutations are checked and we obtain original number exit from loop . ; Driver Program
function countdigits ( N ) { var count = 0 ; while ( N > 0 ) { count ++ ; N = parseInt ( N / 10 ) ; } return count ; } function cyclic ( N ) { var num = N ; var n = countdigits ( N ) ; while ( true ) { document . write ( num + " " ) ; var rem = num % 10 ; var dev = parseInt ( num / 10 ) ; num = parseInt ( ( ( Math . pow ( 10 , n - 1 ) ) * rem + dev ) ) ; if ( num == N ) break ; } } var N = 5674 ; cyclic ( N ) ;