Exhaustion Example 2

Suppose you wanted to find 4 numbers between 1 and 100 that had these properties:  The second one was twice the first.  The third was 3 times the fourth.  The first was equal to the fourth, and they all added together to get 154.  Not an easy task!  But it is simple for the computer.  Look at the ‘Solve by Exhaustion’ template above.  See if you can code this problem in the template (change the if statements)  Check your answer.  The solution is found by scrolling down on this page.  No peeking until you tried on your own!

.

.

.

.

.

.

.

.

.

.

<html>
   <head>
     <script type = “text/javascript”>
         <!–
 
     guess = “rgbycp”;
     numguess=0;

    for (i=0;i<100;i++)
    {
        for (j=0;j<100;j++)
        {
            for (k=0;k<100;k++)
            {
                 for (m=0;m<100;m++)
                 {
                   if(i*2==j)
                     if (m*3==k)
                         if (i==m)
                            if(i+j+k+m==154)
                                 document.write(i+” “+j+” “+k+” “+m+”<br>”);

                 }
            }
        }
    }

     </script>
   </head>  
   </html>

Leave a Reply

Your email address will not be published. Required fields are marked *