Saturday, February 28, 2015

Using Java to solve an AMC 10 problem

Nicholas continues to practice his Java coding. This quickly makes my job hard to find suitable and interesting problems for him to work on. One day when he talked to me about how he solved an AMC 12 problem, it dawned on me that he could use Java to solve the problem:

c^2005 = logab
a+b+c=2005
a>=2, b>=1, c >=0. a, b, c are integers.

When I told him that he could use Java to solve the problem, he could not believe it - he thought that one has to use MATHMATICA to solve equations. In addition, he explained to me that it took reasoning to get the solutions: "Java can not reason, how could you use Java to solve the problem?"

It was a perfect educational moment for me. I showed him how to convert the problem into a programmable problem, I also used the opportunity to show him how to write out the flow chart for a program one more time. When he finally made his code to run, he was exhilarated to find out that the code produced the right solutions as he got!  (2004,1,0), and (1002, 1002, 1).

This week after AMC 10b test, he discussed with me about problem 25 which he did not complete during the real test. After some discussion, we found a way to solve the problem, which is essentially the same as the following question

2ab+2bc+2ca = abc
a>= b>= c >= 1, a,b,c are positive integers.

How many solutions does this problem have?

When it is time for him to practice Java coding this weekend, I recommended that he wrote a code to solve this problem. He happily agreed.  After he converted the problem into programmable problem, make the flow chart, it took him less than 10 minutes to write the code and got the solution without any help from me.

I am sure that after a few such practices, it will be a challenge for me again to find suitable and interesting problems for him to solve using Java.

It is time for him to get into next level of Java coding!
-----
Appendix - the code and solutions

import java.util.*;
public class AMCTwentyFive {

       public static void main(String[] args) {
              int a;
              int b;
              int c;
              int counter=0;
             
              for (c=1;c<=6;c++){
                     for (b=c;b<=1000;b++){
                           for (a=b;a<=1000;a++){
                           int x = 2*a*b+2*a*c+2*b*c-a*b*c;
                            if (x==0){
                                  System.out.print("a = "+a+", ");
                                  System.out.print("b = "+b+", ");
                                  System.out.print("c = "+c);
                                  System.out.println();
                                  counter=counter+1;
                           }
                                 
                           }
                     }
              }
      
       System.out.print("You have found "+counter+" solutions ");          
              }
       }


a = 42, b = 7, c = 3
a = 24, b = 8, c = 3
a = 18, b = 9, c = 3
a = 15, b = 10, c = 3
a = 12, b = 12, c = 3
a = 20, b = 5, c = 4
a = 12, b = 6, c = 4
a = 8, b = 8, c = 4
a = 10, b = 5, c = 5
a = 6, b = 6, c = 6

You have found 10 solutions


Note:  AMC - American Mathematics Competition




No comments:

Post a Comment