Generate k digit numbers with digits in strictly increasing order | number -- > Current value of number . x -- > Current digit to be considered k -- > Remaining number of digits ; Try all possible greater digits ; Generates all well ordered numbers of length k ; Driver code
< ? php function printWellOrdered ( $ number , $ x , $ k ) { if ( $ k == 0 ) { echo $ number , " " ; return ; } for ( $ i = ( $ x + 1 ) ; $ i < 10 ; $ i ++ ) printWellOrdered ( $ number * 10 + $ i , $ i , $ k - 1 ) ; } function generateWellOrdered ( $ k ) { printWellOrdered ( 0 , 0 , $ k ) ; } $ k = 3 ; generateWellOrdered ( $ k ) ; ? >