Epic-desirable number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.