Answered # Algorithm to generate 10-digit numbers

VernonDozier 2,218 Discussion Starter stinkypete VernonDozier 2,218 jaskij 45 Zvjezdan23 -13 Discussion Starter stinkypete Discussion Starter stinkypete VernonDozier 2,218 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

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.

0

By generate I mean that each time round the algorithm, another 10-digit number pops out.

0

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.

0

To be honest with you, I'd say it's not a task for C++, rather a computer algebra system - they tend to cope with similar tasks really well.

Anywas, there is `next_permutation()`

in the STL `algorithm`

header, this should help you using what VernonDozier wrote. Just pick a digit to repeat, make an array(or vector) of them, sort it, then iterate through it's permutations using `next_permutation()`

. Still, you have 10*9!=10!=3,628,800 iterations on your hands.

-1

generate random numbers from 1 to 9??? easy. make a random number generator from 1 to 9 then make an int number_array[10] and have the arrays = random numbers.

0

I want all the numbers, not a random selection.

0

I'm going to mark this thread as solved. Not that my question has been answered, but I don't think it has an answer other then "no-one knows, and probably not".

0

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.

This question has already been answered. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...