The following entries were tagged with “maths”. They are displayed with the most recent entries first. (1–3)

Four Glass Puzzle

Posted in and on Sat, 05th Jan 2008 at 19:30

I learned this puzzle from a friend in work. He posed it one morning before everyone had had their coffee and ended up costing a small handful of engineers a whole morning of productivity as we each solved it. I've been meaning to post about it here for a while. Here's the formulation as best I can describe it:

You have in front of you one of those tables you get in Asian restaurants with the rotating centre—what one of our product managers described as a lazy susan, though I've never heard that phrase from anyone else. Picture the restaurant from the beginning of Indiana Jones and the Temple of Doom if you really want to set the scene.

On the table are four glasses, each of which is either standing upright or turned upside down. They're evenly spaced around the table, in a square. You sit at the table blindfolded. Your aim is to turn the glasses such that they are either all upright or all upside down, subject to the following rules.

You are allowed to inspect two of the glasses, by touch, at a time. You can choose to inspect either the two immediately in front of you (i.e., a side of the square) or one in front of you and the one opposite it (i.e., a diagonal). After inspecting the glasses you are allowed to turn either glass, both glasses or neither glass.

Once you've inspected and possibly turned two glasses the table is rotated a random amount so that you don't know which glass is which. You then have the same choices about inspecting and turning glasses as before. Then the tables is rotated again. It goes on like this for as long as you need to solve the puzzle.

If at any point you get all the glasses upright or all upside down you'll be told that you've won. You don't need to be able to know that you've solved it. You aren't told at the start what configuration the glasses are in, though you can assume they don't start in a solved state.

Find a way to reliably solve this puzzle that will be guaranteed to work in a finite number of moves regardless of the initial conditions or how lucky you are with rotations of the table. In particular this means that you can't just keep spinning the table and turning upright every glass you touch in the hope that you'll get them all eventually.

Comments:
Sat, 05th Jan 2008 (22:00)

First off, I'm not an engineer. Secondly, I thought I had it, then I thought I didn't, then I thought I did…

The big stumbling block is the random turning of the table after the selection of up/down glasses.

So, if it were me, I'd choose a diagonal selection and change both to UP. After every spin, I'd change both diagonal corner glasses to UP. I think this would be the shorterst route to completion.

I do hope you post the answer because this is going to bug me!

by isadub
Sat, 05th Jan 2008 (23:13)

"isadub": Your suggestion would be pretty pragmatic if you were really in that situation, as you'd be very likely to solve it in very few rounds. But technically it's no a solution because it would be possible (though unlikely) to get the same diagonal on every round forever.

I'm going to hold off on posting the solution for a little while, and I'll post it in a new entry after that.

by Rory
Sun, 06th Jan 2008 (00:52)

Come on, Rory! It's hardly physics.

One solution as follows: I'll refer to positions as follows: A B C D

Round 1: Select two glasses on the diagonal B-C. And turn them up correctly. (If the other two glasses are up, then you have already won)

Round 2: Select the C-D line. You are now gauranteed to have selected one and only one of the previous two glasses. -If one glass is up and one upside down, then you know the upside down glass is the new one. In this case flip both glasses so that one of the original pair is now upside down, while the new glass is turned up correctly. -If both glasses are up, then do nothing. -It is impossible for both to be upside down.

At this stage you have either won, or are gauranteed to be in a 3 up 1 upside down configuration.

Round 3: Select the glasses along C-D -If one is up and one is upside down, flip the latter and you win - If both are up then flip one at random

At this stage you have either won, or are gauranteed to be in a 2 up 2 upside down configuration.

Round 4: Select the glasses along B-C -If the glasses are both either up or down, then flip both and you win.

If you are still in the game, you now have two adjacent glasses up and two down.

Round 4: Select the glasses along C-D. -If the glasses are both either up or down, then flip both and you win. If not, flip them anyway. This gaurantees that one diagonal contains glasses pointing up and one contains glasses pointing down.

Round 5: Select the glasses along B-C and flip them. You have now won.

You can do better if you can feel one glass before choosing whether to pick a diagonal or side. You can also do better if you can flip and unflip in one turn.

Do I win a google job? I think I can do the XKCD problem too using combinatorics tricks.

by Joe
Mon, 07th Jan 2008 (10:02)

Rory, your puzzle gave me a stroke. Now I must sue you.

by Ronan Lowe

Maths Fun

Posted in and on Fri, 14th Dec 2007 at 01:00

If you watched the video of Randall Munroe at Google you might have heard him mention a site called Project Euler. It's a cool collection of short but interesting mathematical problems that are intended to be solved with a computer. That said, there's nothing stopping you from using good old practical mathematics.

The most solved puzzle on the site is this one:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Now, this didn't look to me like a computer was required to solve it, so I nibbled the end of my pencil for a second and came up with the following solution:

There will be 333 numbers in that range which are divisible by three (every third number, so a third of the total). There will be 199 numbers in that range that are divisible by five (every fifth number, and a fifth of the total—it's 199 rather than 200 because the top number, 1000, is excluded).

Now I don't know offhand a way to calculate the sum of the first 333 numbers divisible by three. But I do know offhand a way to calculate the sum of the first 333 numbers. It's 333 × 334 ÷ 2. Is that any help? It turns out it is. Consider the first five multiples of three: 3, 6, 9, 12, 15. The sum is 3 + 6 + 9 + 12 + 15 = (3 × 1) + (3 × 2) + (3 × 3) + (3 × 4) + (3 × 5) = 3 × (1 + 2 + 3 + 4 + 5). That is, it's three times the sum of the first five numbers. By the same reasoning, the sum of the first 333 multiples of three is equal to three times the sum of the numbers from one to 333, or 3 × 333 × 334 ÷ 2.

Applying the same reasoning again, the sum of the first 199 multiples of five is five times the sum of the first 199 numbers, or 5 × 199 × 200 ÷ 2.

There's one more piece: in adding up all the multiples of three, and all the multiples of five, I've included some numbers twice. There are some numbers that are divisible by both three and five, i.e., those numbers divisible by fifteen. There are 66 of these, from 15 to 990 (again, by taking 1000 ÷ 15 and rounding down you get 66). So the total has to be reduced by 15 × 66 × 67 ÷ 2.

The final answer is: (3 × 333 × 334 ÷ 2) + (5 × 199 × 200 ÷ 2) - (15 × 66 × 67 ÷ 2) = 233168.

The easy way, of course, is:

$> python
>>> sum([i for i in range(1,1000) if i % 5 == 0 or i % 3 == 0])
233168

Rice Rice Baby

Posted in and on Tue, 13th Mar 2007 at 21:21

Did you ever hear the old Chinese story about the rice and the chessboard? The specifics are hazy, and I'm sure there are lots of variations anyway, but I remember the important details. Someone having performed some important task for the king asked that he be paid in rice. The king was to put one grain of rice on the first square of a chessboard, two on the next, four on the next and so on to fill the board with each square containing twice as much rice as the previous one. How much rice do you think this adds up to?

The answer is easy to calculate but difficult to imagine. There are 2N - 1 grains on the Nth square. 20 = 1 on the first, 21 = 2 on the second, 22 = 4 on the third, and so on. The last square, number 64, has , 263 = 9x1018 grains on it. That's a nine followed by 18 zeros or nine billion billion. Let's try to cut that down to something we can imagine.

There are about 2000 grains, give or take, in a reasonable portion of rice. If a person eats one portion every day she will eat 730,000 grains a year. That last square will feed her for about 1013 (ten thousand billion) years. I think we need to cut it down further.

There are six billion people alive right now. If they all loved rice as much as the example person in the previous paragraph and consumed it at the same rate of 730000 grains a year it would take about 2000 years to eat it all. The only problem is that none of us will live that long. We could eat it at twice the rate, say two portions a day each, but that will only reduce it to 1000 years. We need more people.

It's estimated that there have been somewhere in the region of 100 billion people ever. Let's assume that they all loved rice and would want to eat two portions a day for their entire lives. So we have 100 billion people each eating 1460000 grains of rice per year. How long would it last?

263 grains / (1011 people * 1460000 grains per person per year) = 63 years, a lot more than the average lifespan for most of human history. That single square of rice would comfortably feed two portions a day to every person who has ever lived for their entire life.

The rest of the board contains the same amount again (less one grain).

Comments:
Wed, 14th Mar 2007 (00:43)

And, what if your family don't like rice? They like… cigarettes?

by Eoghan
Wed, 14th Mar 2007 (10:17)

Whats a chinese person? Whats a murder? We do need more people, fortunately because of the origin of that story, the chinese have known this for a long time, and so to help us have begun exporting their largest natural resource as well as cultivating replacement stock.

Thu, 15th Mar 2007 (11:23)

If you take the average portion of rice for a person (50g) to be equal to the weight of 2000 grains, what will be the weight on the final square?

Also, lets say the average chess board has a a single playing square area of 5.5cm^2, and a grain of rice (to be easy lets say it's a cuboid) has an area of 1.5mm^3 (6mm X 0.5mm X 0.5mm, indian rice has a length of between 5.8mm and 6.0mm), how high will the rice on the final stack be?

For the engineer in you: what type of material would the chess board have to be made of to support that weight on one square?

Thu, 15th Mar 2007 (23:03)

Vibrainium … the same stuff as Captain Americas (RIP) shield

by Ronan Lowe