Monday, May 7, 2012

Solve this Puzzle in Python

Hi,

I would like to present you a very interesting puzzle. It was asked by maths teacher in high school ( not to solve in Python, but solve in pen and paper ). I could solve it back then ( where my "method" was not good and the way i found it is still a "mystery" to me. ). Even a few days back, I admit I couldn't find a method to solve this except brute forcing.

So I decided to apply brute-forcing for this puzzle in Python, and I asked this question in stackoverflow.com. But I was really surprised seeing the answers provided there. I would like to share this with you.

This is the puzzle :


A merchant has a 40 kg weight which he used in his shop. Once, it fell from his hands and was broken into 4 pieces. But surprisingly, now he can weigh any weight between 1 kg to 40 kg with the combination of these 4 pieces.
So question is, what are weights of those 4 pieces?
Try to solve this puzzle in Python. If you can't, find its answer here.
With Regards,
ARK.

2 comments:

  1. There's a property of powers of 3 which is used for such problems.

    ReplyDelete
    Replies
    1. Yeah. I haven't known about it. Do you know more about this? Can you share it with us?

      Delete