Originally Posted by

**unsolicited**
Can i ask how you can *see* that? (I know that's a weird question)

Like, i was trying to draw out nested loops on paper to get a mental idea of how they might interact. But I still can't see it.

For me, it's all about looking for patterns and relationships between values.

Given your example ....

Code:

deck_card[0] goes to player[0][0]
deck_card[1] goes to player[1][0]
deck_card[2] goes to player[2][0]
deck_card[3] goes to player[0][1]
deck_card[4] goes to player[1][1]
deck_card[5] goes to player[2][1]
deck_card[6] goes to player[0][2]
etc...

I picture it as a mapping of the form card_deck[i] -> player[j][k]. This means, for every value if i there must be a j and a k.

For mapping i to j, the examples are

Code:

0->0
1->1
2->2
3->0
4->1
5->2
6->0

The values on the right show a pattern i.e. 0,1,2,0,1,2,.... I then ask what sort of thing produces a sequence like that. It cycles every 3, and ramps up one step at a time from 0 to 2. In other words, j is always the remainder when dividing something (which is related to i somehow) by 3. j = i %3 does the trick.

For mapping i to k, it is a similar thing.

Code:

0->0
1->0
2->0
3->1
4->1
5->1
6->2

This time, however, the pattern is 0,0,0,1,1,1,2 In other words three values the same, then increment, then repeat. What gives that sort of pattern: integer division, that's what. 0/3 = 0, 1/3 = 0, 2/3 = 0, 3/3 = 1, etc/ So k = i/3.

Originally Posted by

**unsolicited**
And thank you **grumpy** for the math hint.

But that's not happening in my lifetime. My math skills are utter garbage.

I understand what both of those operators do*, but applying them creatively is beyond me.

Frankly, you're going to need to increase your basic math skills if you want to be able to do this sort of stuff - this particular problem is primary school stuff. If you insist on treating mathematics as something you recite by rote, rather than as something to understand and think about, you'll never get it. For people who look at mathematics as something to __understand__ rather than to __recite__, it is easy. The basics concepts for answering your question, in this case, are integer arithmetic.

The reason I gave you an __elementary__ math answer is that you asked a theoretical question (that is your subject line on this thread). Mathematics is a basic language for articulating the theory you asked about.