Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

4 numbers that multiply to make 120

Name: Anonymous 2007-03-09 16:50 ID:yO9TuDQD

I suck pretty hard and can't figure out a way to do this, I am doing it in php, cause it's pretty much all I know..
so I tried
<?php
$v1=1;
$v2=1;
$v3=1;
$v4=1;
$v5=1;

while ($v4 < 10) {
    print "$v1 * $v2 * $v3 * $v4 = $v5<br>\n";
    $v1++;
    $v5 = $v1 * $v2 * $v3 * $v4;
    print "$v1 * $v2 * $v3 * $v4 = $v5<br>\n";
    $v2++;
    $v5 = $v1 * $v2 * $v3 * $v4;
    print "$v1 * $v2 * $v3 * $v4 = $v5<br>\n";
    $v3++;
    $v5 = $v1 * $v2 * $v3 * $v4;
    print "$v1 * $v2 * $v3 * $v4 = $v5<br>\n";
    $v4++;
    $v5 = $v1 * $v2 * $v3 * $v4;
    print "$v1 * $v2 * $v3 * $v4 = $v5<br>\n";
    }
 
print "FINISHED AND SHIT";
?>
which obviously doesn't work as it just does
1 * 1 * 1 * 1 = 1
2 * 1 * 1 * 1 = 2
2 * 2 * 1 * 1 = 4
2 * 2 * 2 * 1 = 8 etc.
missing out lots of numbers.

tl;dr how do i make php find out what 4 numbers multiply together to make 120.

Name: Anonymous 2007-03-09 18:01 ID:/Y+haGsO

first of all there are more than 256 unique products a*b*c*d where a,b,c,d are in {1,...,9}. there are (4+9-1,4)=495 unique products. use something like this (pseudocode):


for (a=1;a<=9;a++)
  for (b=a;b<=9;b++)
    for (c=b;c<=9;c++)
      for (d=c;d<=9;d++)
        print a*b*c*d


dont start the loops at 1 otherwise you will enumerate the same product multiple times: 2*1*1*1, 1*2*1*1, 1*1*2*1, 1*1*1*2, etc

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List