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 .
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 162 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
9 | pajenegod | 145 |
9 | SecondThread | 145 |
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 .
Name |
---|
brute-force
Not able to understand it. A c-code will be helpful or an algorithm.
From each lucky number X we can generate two lucky numbers — 10 * X + 4 and 10 * X + 7.
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.
You can find it with recursive.
There's at most 21 + 22 + 23...210 = 2046 lucky numbers.
Here's my code
Here's a cleaner, easier and faster solution simply using strings, if anybody comes back to look at this thread