# How to determine the weight of a coin from each of the $4$ bags.

We are given $4$ bags of coins such that (a) all coins in a given bag weigh the same, and (b) the coins of a given bag weigh either $1,2,$ or $3$ ounces. Take $1$ coin from bag $1,3$ coins from bag $2,9$ coins from bag $3$, and $27$ coins from bag $4$. Weighing these $40$ coins together on a scale yields a weight of $95$ ounces. Determine the weight of a coin from each of the $4$ bags.

I've been trying to solve the problem by setting up the equation $x+3y+9z+27w=95$ where $x,y,z,w \in (1,2,3)$ and trying up some values,but this is just taking me forever.

Is there some slicker way to do the problem ?

Hint:

If you consider your equation $x+3y+9z+27w=95$ modulo $3$. You will get $$x\equiv 2 \pmod{3}.$$ Based on the fact that $x \in \{1,2,3\}$, you get $x=2$. For $y$ try modulo $9$ and so on. Hopefully you can handle the rest.

• Nice hint ,thanks.Where did you get the idea to work in modulo $3$?It seems to me as completely non-intuitive. – Mr. Y Nov 25 '15 at 20:03
• @Mr.Y If you look at the coefficients of $y,z$ and $w$, they are all multiples of $3$. So if I want to isolate $x$, then the best strategy will be to somehow make $y,z$ and $w$ disappear :-) hence $\mod 3$. Also that is why I chose $\mod 9$ for $y$ because now I already know $x$ and have to make $w$ disappear. – Anurag A Nov 25 '15 at 20:06

Hint:

• The $13$ coins from bags $1,2,3$ weigh from $13$ through to $39$ ounces so the $27$ coins from bag $4$ weigh from ... through to ... and so must weigh ... each and ... in total, leaving ... for the $13$ coins.

• The $4$ coins from bags $1,2$ weigh from $4$ through to $12$ ounces so the $9$ coins from bag $3$ weigh from ... through to ... and so must weigh ... each and ... in total, leaving ... for the $4$ coins.

• ...

Here is some R code that solves your problem:

#Matrix for saving results
mat <- matrix(NA,ncol = 1,nrow = 4)
colnames(mat) <- c("x","y","z","w")

#Loop through all possible values
for (x in c(1,2,3)){
for (y in c(1,2,3)){
for (z in c(1,2,3)){
for (w in c(1,2,3)){

if(x+3*y+9*z+27*w == 95){

mat <- cbind(mat,c(x,y,z,w))

}

}
}
}
}


The result is $x = 2$, $y = z = 1$, $w = 3$.

If you set $x' = x - 1$, $y' = y - 1$, $z' = z - 1$, and $w' = w - 1$, then $x', y', z', w' \in \{0, 1, 2\},$ and $x+3y+9z+27w=95$ implies that

$$55 = 3^3 w' + 3^2 z' + 3y' + x'.$$

So basically you are being asked to convert the decimal number $55$ to base three. The answer is

$$55_{10} = 2001_3,$$

which implies that $(w', z', y', x') = (2, 0, 0, 1)$ and so $w = 3$, $z = 1$, $y = 1$, and $x = 2$.

• Wow this is absolutely genial ! Where did you have the idea from ?!Can you share your insight ?I mean it's not really intuitive the way you have set up $x,y,z,w$. – Mr. Y Nov 26 '15 at 9:07
• The first insight was that since each variable $x,y,z,w$ has to be at least $1$, change each of them to $1$ plus the "extra" amount. This is a way to simplify many problems, not just this one. In this problem, the "extra" amount is $0$, $1$, or $2$. These look like digits base $3$, and they are multiplied by $1, 3, 9, 27,$ which are the first four place values in base $3$. Four base-$3$ digits multiplied by the first four base-$3$ place values is a base-$3$ number. – David K Nov 26 '15 at 14:02

There are some great solutions here, but there is a far simpler way of approaching this problem.

Address this problem starting with the variables of highest coefficient.

Thus, we clearly start with $w$. Notice that if you plug in $2$ for $w$, you have $54$ oz. Plugging in $3$ for the remaining variables, your total weight comes up short at only $93$ oz. Therefore, $w$ must be $3$.

Since $w$ is $3$, you already have $81$ oz. Now let's look at $z$. Plugging in any value other than $1$ for $z$ yields a total of over $95$, so $z$ must be $1$.

Now we look at $y$. Since we now have $90$ oz. of coins, plugging in any value other than $1$ for $y$ gets us over our total again. Therefore, $y=1$.

We now have the equation $x+93=95$. $x$ must be $2$.

Nothing complicated.