Does anyone have an algorithm that generates all 10-digit integers that have at least one digit repeated? Trawling through all 9000000000 of them and checking them individually is too slow. Thanks.
10 digit number, 10 digits, none repeated, sounds like you can generate all permutations of 0123456789, then throw out the ones that start with 0. The set of ten digit numbers MINUS this set is your answer. The set of all 10-digit integers that have at least one digit repeated is far larger than the set if 10-digit integers without repeats, so you're dealing with close to 9000000000 anyway, so if you have to "generate" them all (what precisely does "generate" mean here?), you can either "trawl" through them as you said or you can start with all of them, then remove the ones I mentioned. Either way seems like a long runtime.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
10! is 3,628,800. 10 to the 10th power is 10 billion. Take away the numbers that start with 0 and that's what you're working with. You have, again, two options. One way or another, you have a loop of 9 billion if you need to "pop out" a number each time. You can either have an array or vector or set or whatever of the numbers that don't have repeated digits and check against that 9 billion times, or you can test each number by going through all ten digits 9 billion times. I imagine the former is faster than the latter, but a little testing will tell.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
It does have an answer, lots of people do know how to do it, including me, and I tried to explain how I would do it.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711