Breaking_Benjamin's blog

By Breaking_Benjamin, 10 years ago, In English

Consider Lucky numbers to be numbers with only digits 4 or 7 . Repetition is allowed. We need to generate all lucky number below 1010 in ascending order. What is the algorithm to do it ? Please explain it .

  • Vote: I like it
  • -8
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it
  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Not able to understand it. A c-code will be helpful or an algorithm.

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +7 Vote: I do not like it

      From each lucky number X we can generate two lucky numbers — 10 * X + 4 and 10 * X + 7.

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    i think ur lines 58 and 65 (both having lucky.insert(nval);) are not needed because of ur line 54 (lucky.insert(val);).
    alternatively, u could remove lines 53 and 54, and leave the rest of ur program as is.

»
10 years ago, # |
  Vote: I like it +8 Vote: I do not like it

You can find it with recursive.
There's at most 21 + 22 + 23...210 = 2046 lucky numbers.
Here's my code

»
7 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Here's a cleaner, easier and faster solution simply using strings, if anybody comes back to look at this thread