ThreeNPlus1 solution

<?php
/*
 * Created on Feb 13, 2008
 *
 * In class example.
 * Write a PHP script that computes the 3N+1 problem. For N > 0,
 *  generate a sequence of numbers using the following simple rules:
 *  if N is even, divide it by 2; if N is odd, multiply it by 3 and add 1.
 *  The sequence always converges to 1, although the length of the sequence
 *  varies depending on the choice of N.
 *
 */
?>
<HTML>
  <HEAD>
    <TITLE>3N + 1 Problem</TITLE>
  </HEAD>
  <BODY>
    <H4>The 3N + 1 Problem</h4>
    <?php
       $n = 8;
       echo "N= $n<BR>";
       while ($n > 1) {        // While n is greater than 1
           echo "$n<BR>";      // Print it then either
           if ($n % 2 == 0) {
               $n = $n / 2;    //  Divide it by 2
           }
           else {
               $n = 3 * $n + 1;  // Or multiply 3N+1
           }
       }
    ?>
  </BODY>
</HTML>