Not Yet Answered # combination of a three digited number

zeeven mvmalderen 2,072 JamesCherrill 2,785 mvmalderen 2,072 JamesCherrill 2,785 mvmalderen 2,072 JamesCherrill 2,785 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

so ur trying do a permutation if i not wrong (or a combination maybe). it would be a long story to ellaborate it. try to search the net for the permutation algorithm. I've done that same program you should understand the algo and try to code it. if your stucked then that's the time to seek help.

0

Well, I know an algorithm:

The first step is concatenating the number one time after itself.

This will give us the opportunity to easily find the first part of the possibilities.

The second step is, reverse all the possibilities we've got in the first step, and that will give us the second part of the possibilities.

I'll demonstrate this using an example:

I'll take number **123**, we paste the number one time after itself, we become this: **123123**, this will give us the first part of the possibilities:

We can loop through the whole thing and each time shift one digit to get the next possibility:

- 1st possibility is: 123 (
**[123]**123) - 2nd possibility is: 231 (1
**[231]**23) - 3rd possibility is: 312 (12
**[312]**3)

If we now shift one extra time, we get the number where we started with, so here we stop.

Now we just reverse all the possibilities we've got in the first step, to get the second part of the possibilities:

- 4rd possibility: 321 (reverse of 123)
- 5th possibility: 132 (reverse of 231)
- 6th possibility: 213 (reverse of 312)

And now we've got all the possibilities :)

0

Well, I know an algorithm: ... :)

Is there a version that scales for arbitrary length, or is it just a special case for length = 3?

0

Is there a version that scales for arbitrary length, or is it just a special case for length = 3?

Well, I guess it works for every number.

But feel free to tell me that I'm wrong

(If you find a number where this algorithm won't operate correctly on).

Edit:: No, it doesn't work for every number :(

0

If you use it literally for a 4 char string you will get 8 results, when it should be 24, 5 chars = 10 results, not 60, so if there is a general version it obviously needs to be a bit more cunning then the 3-char case...

0

Well, apparently I was wrong, but it **will** work for numbers which consist out of three digits :)

0

... it

willwork for numbers which consist out of three digits :)

Yes, definitely. I was just hoping that it was a special case of a more general algorithm that could save all that tedious recursion, but apparently not. Interesting, anyway.

This article has been dead for over six months. 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 ...