Jump to content

[SOLVED] generating every combination of 3 wheels from 1 to 16


Fog Juice

Recommended Posts

Hello,

 

Suppose the following:

$wh1 = rand(1, 16);
$wh2 = rand(1, 16);
$wh3 = rand(1, 16);

 

I want to generate every combination of $wh1, $wh2, and $wh3. There will be 4,096 different combination but I want to print them out in a list for a little app I'm making. Before I even get started on doing this, can someone suggest what might be a better way to do this? I enjoy php but my math skills are not so great.

 

 

Thanks.

$result = array();
for ($wh1 = 1; $wh1 <= 16; ++$wh1) {
for ($wh2 = 1; $wh2 <= 16; ++$wh2) {
	for ($wh3 = 1; $wh3 <= 16; ++$wh3) {
		$result[] = array($wh1, $wh2, $wh3);
	}
}
}

 

damn you, I figured it out and was just about to post solution and close the thread but you beat me to it. lol. I thought it would be something more complicated.

 

Thanks :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.