Thursday, May 25, 2006

A mathematical problem

Today Miguel Baulíes has put me the following exercise:

Being A, B, C numbers between 0 and 9, if
   ABC
ABC
+ ABC
-------
BBB

¿What are the values of A, B and C?

Firstly I tried with a system of equations, but could only make 1 equation:
3 * ( 100*A + 10*B + C ) = 100*B + 10*B + B

which simplifies to
300*A + 3*C = 81*B

Having only one equation and 3 unknown values was no good, so I tried the numerical approach making a bash script:

···································································

for a in 1 2 3 4 5 6 7 8 9 0
do
for b in 1 2 3 4 5 6 7 8 9 0
do
for c in 1 2 3 4 5 6 7 8 9 0
do
let "resul = 300 * $a + 3 * $c"
let "resul2 = 81 * $b"
if [ $resul == $resul2 ]
then
echo $a $b $c
fi
done
done
done

..................................................................


This yielded the result (actually two different ones, but I'm not telling: they don't fit in this post), but I was a bit dissapointed because I wanted to solve the problem using a system of equations. I think it must be possible, but can't think of the other 2 different equations that I need.

Then again, it was just a pastime, and it made me pass some time, and that was the whole point, wasn't it?.

1 comment:

  1. Hey Sam!

    Today I was a little bored at office and I thought, let's take a look at Sam's blog.

    Hehe, you are right, there is another way of solving this. I supose it is not the easiest but....

    I better write an email and send it to you ;)

    ReplyDelete