A number is called ' desirable ' if any thedigits is strictly ascending eg:159 as 1<5<9. You know this your rivalhas a strictly numeric password that's is ' desirable '. Your close ally have givenyou the number of digits (N) in Your rival ' s password. WAP Th\hjtat takes in ' N ' as-input and prints out-all possible ' desirable ' numbers so can be formedwith N digits.
Recursion: Parameters record the length of the remaining required and the minimum number of append to be generated
def BFS (remain,start,string) if remain = = 0<< string Else (start : 9). Each {|i| BFS (remain-1, i+1, string + i.to_s)} endenddef desire_number (n) = [] BFS (n,1,') @ansend
Loop: Save the case of i-1 with two arrays and I from 1 to n
def Desire_number (N)
return 0 if n = = 0= ['1'] (n-1). times do = [] A.each {|x| (X[-1].to_i. 9). each{|y| b << x+y.to_s}} = b end Aend
Epic-desirable number