Jump to content

Very advance math


Jragon

Recommended Posts

<html>
<head>
  <title>Hats</title>
</head>

<body>
<?php

/*
Rules:
1 hat must be worn all day
A hat must be worn every weekday
Cant change hat once put on in the moring

Mathmatical Statment
4*4*4*4*4 = 1024

What is going to happen:
Every statment will be echoed out

E.G:
 <table>
  <tr>
   <th>Monday</th>
   <th>Tuseday</th>
   <th>Wesnesday</th>
   <th>Thesday</th>
   <th>Friday</th>
   </tr><tr>
   <td>Pink</td>
   <td>Brown</td>
   <td>Blue</td>
   <td>Red</td>
   <td>Red</td>
  </tr>
 </table>
*/

$hat1 = 'Pink';
$hat2 = 'Brown';
$hat3 = 'Blue';
$hat4 = 'Red';
$odd = true;

while ($num <= 1024){

}

?>
</body>
</html>

 

If you reed the notes it says what i want to do

 

If anyone has any ideas how i can do this it would be cool

 

Thanks

 

Jragon

 

Link to comment
Share on other sites

The point is it doesn't say how the variables you have are related to do output you want. The simplest way is just to echo what you want.

 

echo "<table>
  <tr>
   <th>Monday</th>
   <th>Tuseday</th>
   <th>Wesnesday</th>
   <th>Thesday</th>
   <th>Friday</th>
   </tr><tr>
   <td>Pink</td>
   <td>Brown</td>
   <td>Blue</td>
   <td>Red</td>
   <td>Red</td>
  </tr>
</table>";

 

but I suspect it's not what you're after is it?

Link to comment
Share on other sites

No.

 

Because I'm lasy and dont want to make a table my self for each differnt time.

 

I want php to do it for me using somthing like a while loop or a for loop

 

in the end it would make somthing like this:

<table>

 

 

 

  <tr>

 

 

 

  <th>Monday</th>

 

 

 

  <th>Tuseday</th>

 

 

 

  <th>Wesnesday</th>

 

 

 

  <th>Thesday</th>

 

 

 

  <th>Friday</th>

 

 

 

  </tr><tr>

 

 

 

  <td>Pink</td>

 

 

 

  <td>Brown</td>

 

 

 

  <td>Blue</td>

 

 

 

  <td>Red</td>

 

 

 

  <td>Red</td>

 

 

 

  </tr><tr>

  <td>pink</td>

<td>pink</td>

<td>pink</td>

<td>pink</td>

<td>pink</td>

  </tr>

<tr>

 

  <td>blue</td>

<td>blue</td>

<td>blue</td>

<td>blue</td>

<td>blue</td>

 

 

 

</table>

 

ect.

 

But i  have no idea how to do this

Link to comment
Share on other sites

sort ov. the first paragraph is almost correct

 

eddited verstion:

In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging in an ordered fashion) objects or values. Informally, a permutation of a set of values is an arrangement of those values into a particular order. Thus there are six permutations of the set {1,2,3}, namely [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1], [3,3,3], [2,2,2], [1,1,1], [3,3,2], [3,2,3] ECT.

Link to comment
Share on other sites

Permutations with repetitions then. The crude way looks like this.

 

$hats = array('pink','brown','blue','red');

foreach($hats as $hat1) {
  foreach($hats as $hat2) {
foreach($hats as $hat3) {
  foreach($hats as $hat4) {
    foreach($hats as $hat5) {
	  echo $hat1." ".$hat2." ".$hat3." ".$hat4." ".$hat5.PHP_EOL;
        }
      }
    }
  }
}

 

Link to comment
Share on other sites

Come on... is it that difficult to add <tr> and <td> tags to this echo?

 

And as far as foreach goes... here's manual: foreach

 

I've created a recursive function in the meantime, but I'm afraid of even showing it to you...

Link to comment
Share on other sites

Also when i am trying to add numbers to it i get this error

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\mathstatment.php  on line 56

 

my code:

$hats = array('pink','brown','blue','red');
$i = 1;
foreach($hats as $hat1) {
  foreach($hats as $hat2) {
   foreach($hats as $hat3) {
     foreach($hats as $hat4) {
       foreach($hats as $hat5) {
        echo $i . $hat1 . " " . $hat2 . " " . $hat3 . " " . $hat4 . " " . $hat5 . PHP_EOL . '<br />';
        $i++;
      }
    }
  }
}

 

 

Link to comment
Share on other sites

I gave you a direct link to foreach manual page... how can you not find it?

 

PHP_EOL is a line break. I use it because I ran this script in console. For HTML you should use <br/>

 

Here's my recursive function if you're interested:

<?php

function permute($array,$positions,&$perms,$previous = null) {
  if($positions > 0) {
if(!isset($previous)) {
  $previous = array();
}

    foreach($array as $element) {
  $tempPrevious = $previous;
  $tempPrevious[] = $element;
  permute($array,$positions-1,$perms,$tempPrevious);
}
  } else {
    $perms[] = $previous;
  }
}

$perms = array();
$hats = array('pink','brown','blue','red');
$days = 5;

permute($hats, $days, $perms);

echo "<table>";
foreach($perms as $key => $row) {
  echo "<tr><td>".($key+1)."</td>";
  foreach($row as $hat) {
    echo "<td>$hat</td>";
  }
  echo "</tr>".PHP_EOL;
}
echo "</table>";

 

Link to comment
Share on other sites

This is mine

 

<html>
<head>
  <title>Hats</title>
  <style type="text/css">
   th { background-color: #999;}
   .odd_row { background-color: #EEE; }
   .even_row { background-color: #FFF; }
  </style>
</head>

<body>
  <table border="0">
   <tr>
<th>Number</th>
    <th>Monday</th>
<th>Tuseday</th>
<th>Wesnesday</th>
<th>Thesday</th>
<th>Friday</th>
   </tr>
<?php

/*
Rules:
1 hat must be worn all day
A hat must be worn every weekday
Cant change hat once put on in the moring

Mathmatical Statment
4*4*4*4*4 = 1024

What is going to happen:
Every statment will be echoed out

E.G:
 <table>
  <tr>
   <th>Monday</th>
   <th>Tuseday</th>
   <th>Wesnesday</th>
   <th>Thesday</th>
   <th>Friday</th>
   </tr><tr>
   <td>Pink</td>
   <td>Brown</td>
   <td>Blue</td>
   <td>Red</td>
   <td>Red</td>
  </tr>
 </table>
*/

$hats = array('pink','brown','blue','red');
$i = 1;
foreach($hats as $hat1) {
  foreach($hats as $hat2) {
   foreach($hats as $hat3) {
     foreach($hats as $hat4) {
       foreach($hats as $hat5) {
echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';
echo <<<ENDHTML
<td>{$i}</td>
<td>{$hat1}</td>
<td>{$hat2}</td>
<td>{$hat3}</td>
<td>{$hat4}</td>
<td>{$hat5}</td>
</tr>
ENDHTML;
        $odd = !$odd;
        $i++;
        }
      }
    }
  }
}
?>
  </table>
</body>
</html>

 

Thanks for the help

 

Jragon

Link to comment
Share on other sites

For ultimate fun do

 

echo <<<ENDHTML
<td>{$i}</td>
<td style="background: {$hat1};">{$hat1}</td>
<td style="background: {$hat2};">{$hat2}</td>
<td style="background: {$hat3};">{$hat3}</td>
<td style="background: {$hat4};">{$hat4}</td>
<td style="background: {$hat5};">{$hat5}</td>
</tr>
ENDHTML;

 

;)

Link to comment
Share on other sites

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.