0
votes

all out of ideas so looking for help. So I have two tables with a single column with ID's 1-29, each ID represents a coworker. I have a 3rd table where I have already created every combination of records from the first 2 tables.

The part that I am struggling with is that I need to order my 3rd tables as follows, say person 1 calls person 2, the ID in table 3 will look like this: '1-2', now I need to make the next record start with 2 and have person 2 call someone who is not person 1 (who has already been called) and have person 1 not be called again until the remaining 28 people are already called as to ensure that everyone gets called at least once before looking through to other combos.

It's a bit hard to explain so I am willing to elaborate if needed.

For those wondering, the purpose of this exercise to to create a bit of "call train" to have everyone check up on everyone else. Thanks in advance!

2
If I understand this correctly, if you truly want "every possible combination", there are around 28! ~= 10^29 combinations. This would likely take more storage than the total storage of all computers in the world.Kevin Wang

2 Answers

0
votes

You could set up the call chain as follows:

enter image description here

So in Stage 2 1 would call 3 and 2 would call 4 at the same time,etc. At each stage the number of callers would be double the number of callers from the previous stage.

(it is possible to map this into a tree structure)

EDIT#1:

I generated the pattern with this small VBA macro:

Sub Peak()
    Dim stage As Long, i As Long, j As Long, K As Long

    K = 1
    j = 1

    For stage = 1 To 5
        For i = 1 To j
            Cells(K, 1) = i
            Cells(K, 2) = K + 1
            K = K + 1
        Next i
        j = j * 2
    Next stage
End Sub

But a formula-based solution should also be possible.

EDIT#2:

In A1 enter 1
in B1 enter 2

In A2 enter:

=IF(ROWS($1:2)=2*A1,1,1+A1)  and copy downwards.

In B2 enter:

=B1+1 and copy downwards

enter image description here

0
votes

It turns out that 29 is really good for this because it is prime.

What you do is have each call the next on the first cycle, then each call with a gap of 2 on the second, then a gap of 3, and so on. That results in this pattern:

1 2 ... 29
1 3 5 ... 28
1 4 8 ... 27
.
.
.
1 29 28 ... 2

And you have your 28 call trains, using each possible call only once.

Therefore the first record is 1-2. The second record is 2-3 and so on. Until the 29th record is 29-1. Then we start gaps of 2 to get 1-3 and so on.

We can even figure out a formula for that.

In general the nth record is going to be in the i = 1 + (n div 29)th cycle. (I'm using PostgreSQL SQL operators here. div means "division and drop the fraction".) It is the j = (n mod 29)th entry in that cycle (mod means the remainder after integer division). Which means that the call starts at (1 + (j-1)*i) mod 29 and goes to (1 + j*i) mod 29.