Jump to content

Recommended Posts

Hi all,

I'm trying to list the possible combinations in fraction from 1/1 + 1/1 until 9/9 + 9/9. So i came up with this

<?php
//numbers of combination for w/x + y/z
$num1=1;
$den1=1;
$num2=1;
$den2=1;
$row=1;
for($w=0; $w<9; $w++){
echo $row.') ';
$row=$row+1;
echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>';
$num1=$num1+1;

for($x=0; $x<9; $x++){
	echo $row.') ';
	$row=$row+1;
	echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>';
	$den1=$den1+1;

	for($y=0; $y<9; $y++){
		echo $row.') ';
		$row=$row+1;
		echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>';
		$num2=$num2+1;

		for($z=0; $z<9; $z++){
			echo $row.') ';
			$row=$row+1;
			echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>';
			$den2=$den2+1;
		}
	}
}
}
?>

The problem is it parse all the way to

7380) 10/82 + 730/6561.

Where did it go wrong? Thanx in advance...

just do

<?php
//numbers of combination for w/x + y/z
$num1=1;
$den1=1;
$num2=1;
$den2=1;
$row=1;
for($num1=1; $num1<=9; $num1++){
for($den1=1; $den1<=9; $den1++){
	for($num2=1; $num2<=9; $num2++){
		for($den2=1; $den2<=9; $den2++){
			echo $row.'. ) ';
			$row=$row+1;
			echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>';
		}
	}
}
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.