Happy Monday everyone!
Today's goal is to determine the amount of unique integers in the range [0-1000000]. A unique integer is an integer with no duplicates of numbers. 7 and 18 are unique whereas 99 and 100 are not. Your program should print out just the final count of total unique integers.
Comments:
Anonymous - 9 years, 10 months ago
Final: 168,570
reply permalink
David - 9 years, 9 months ago
This has an off by one error for not including "0".
reply permalink
Kevin Benton - 9 years, 10 months ago
168571
len([x for x in xrange(0, 1000000) if len(str(x)) == len(set(str(x)))])
Another one that doesn't need a big listreply permalink
Jtmach - 9 years, 10 months ago
Final 168,571 don't forget about 0.
Javascript
reply permalink
Eddy - 9 years, 10 months ago
My solution in C using only arithmetic and bitwise operations.
reply permalink
David - 9 years, 9 months ago
I decided to do this mathematically using permutations.
One day I will get fancy and upload my scratch work up to git so I can just link it, like Eddy.
Here is my counting in C.
I needed to build my permutation function n!/(n-r)! so it took a little extra overhead in that regard. I ran the permutations of [1,9] for various numbers of digits and added in the cases for then 0 being inserted after any existing digit.
reply permalink