A lucky number is one that contains only 3s or only 7s (such as 77 or 333). A number can also be considered lucky if the length of the number is 3 or 7 (such as 249). Given this knowledge can you compute how many lucky numbers exist in the range [0-1000000]?
Comments:
JtMach - 9 years, 10 months ago
Lucky Numbers: 911
Javascript
reply permalink
Kevin Benton - 9 years, 10 months ago
I only got 900...
reply permalink
Aaron Frase - 9 years, 10 months ago
You're comparing a set of strings with a set of integers so you missed 10.
This fixes it.
nums = [x for x in xrange(1000000) if set(str(x)) in [set(['3']), set(['7'])] or len(str(x)) in (7,3)]
Here was my original (much longer) version
reply permalink
slp - 9 years, 10 months ago
Lucky Numbers: 911
PHP
reply permalink
Eddy - 9 years, 10 months ago
My solution in C code using only basic arithmetic and as few lines of code as I could.
reply permalink