Tip the Scales

Given a balance scale, and a set of 4 weights, weighing 1, 3, 9, and 27 grams respectively, one can accurately measure the weight of any unknown object of weight 1, 2, 3, ... 38, 39, or 40 grams. For example, to identify an object X as being 5 grams in weight, one could simply place:

  • 1, 3, and X on the left
  • 9 on the right

If and only if the scale balances, X weighs 5 grams. More importantly, for any X with weight 1 to 40, there exists exactly one unique configuration of weights that measures X (if we force X to be on the left).

Suppose we always put X on the left. What, then, is the sum of the weights on the right, across all 40 unique configurations?


An explicit example: If we only count unknown weights 1 to 4, we get the following 4 configurations:

  • X <-> 1
  • X + 1 <-> 3
  • X <-> 3
  • X <-> 3 + 1

The sum of the weights on the right across all 4 configurations is 11 :

( 1 ) + ( 3 ) + ( 3 ) + ( 3 + 1 ) = 1 + 3 + 3 + 4 = 11 (1) + (3) + (3) + (3 + 1) = 1 + 3 + 3 + 4 = 11


The answer is 950.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Daniel Ploch
Aug 15, 2014

There are multiple ways to get to the answer here, some involving clever pattern observations. The simplest, brute-force approach is to enumerate all possible arrangements of weights, and simply sum the weights on the right hand side if and only if it is larger than the left.


Here's some python:

from itertools import product

weights = [1, 3, 9, 27]
sum_right = 0
# 0 = not on scale, 1 = left, 2 = right
for positions in product(*([[0, 1, 2]] * 4)):
  left = sum([weights[x] for x in range(0,4) if positions[x] == 1])
  right = sum([weights[x] for x in range(0,4) if positions[x] == 2])
  if left < right:
    sum_right += right

print sum_right # 950

Have the same solution.Glad to see it fixed.I sent the dispute btw. :)

Thaddeus Abiy - 6 years, 10 months ago

Log in to reply

Much appreciated ^^

Daniel Ploch - 6 years, 10 months ago

I worked it out with a pencil, 3 highlighters and a paper. Easy if you realise that the 27 is needed for the final 27 configuration.

ZhiJie Goh - 6 years, 9 months ago

By the way, I know as much about Python as your great-great-grandmother. Where can I find it, and learn to use it?

ZhiJie Goh - 6 years, 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...