Tuesday, October 11, 2011

Is that cheating?

“That’s cheating,” my son was telling me, although he had a grin on his face from ear to ear. He had come home from school with a fun math problem to do for kicks and I solved it in just a few minutes – by writing a program.

So are alternate solutions that use technology cheating? Does the creator of the solution demonstrate less skill when solving a problem in a way that the author of the problem did not think of? In some cases the answer seems to be clearly yes. I do not want my children using a calculator when they are trying to learn their math facts. However, in other cases I am not so sure.

Here is this problem and the alternate solution. You can be the judge if it is “cheating” or not.

Problem: What are three three-digit numbers where the second number is twice the first and the third number is three times the first. In addition, the three numbers together use every digit from 1-9 just once.

Solution via Java (this program actually found four different solutions):

import java.util.*;
public class FindNum
{
public static void main(String[] args)
{
for(int x=100; x<1000/3; x++)
{
int y = x*2;
int z = x*3;

//Throw each digit into a set
//Note: Sets ignore duplicate valules
Set<Integer> digitSet = new TreeSet<Integer>();
digitSet.add(x/100);
digitSet.add(x/10%10);
digitSet.add(x%10);
digitSet.add(y/100);
digitSet.add(y/10%10);
digitSet.add(y%10);
digitSet.add(z/100);
digitSet.add(z/10%10);
digitSet.add(z%10);
//if there are nine digits in the set and no
//zero, we win!
if(digitSet.size()==9&&!digitSet.contains(0))
{
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println();
}
}
}
}