Copyright © 2004 by Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted.
At lunch the other day, a coworker told the rest of us a logic puzzle. We had some good discussion about the solution, but because I'm a programmer, I wrote a program to simulate the answer.
Here's the description of the puzzle.
Here's the problem set-up.
Starting with the setup from the Given section, do these steps:
In case it matters, for this problem, a ``pinch'' of something always has the same size. For example, if a pinch of salt has 100 grains of salt, then a pinch of pepper has 100 grains of pepper.
After doing the steps in the Action section, the salt shaker will contain a certain volume of a salt-&-pepper mixture. The pepper shaker will contain a certain volume of another salt-&-pepper mixture. Each of those mixtures will have its own concentration of salt relative to pepper.
Answer this: Are the two volumes the same? Is the concentration of salt in the salt shaker's mixture the same as the concentration of pepper in the pepper shaker's mixture?
I'm a programmer, so I wrote a simulation program to help me figure out the answer to the riddle.
My program creates a salt shaker & a pepper shaker. It fills each with the appropriate compound. It copies a pinch of salt into the pepper shaker, shuffles it, & copies a pinch back. Then it prints the concentrations of each shaker. If the concentrations are not equal, it also prints a splat character (*).
My usual preference is Lisp, but I didn't have a Lisp system available at work, so I wrote the simulation in C.
The files for my program are these:
I didn't do the full ``./configure; make all check install'' trick. Instead, just edit the Makefile & then run make. That should get you a program called salt. Then run ./go, which will create three output files: out-010.txt, out-100.txt, & out-500.txt.
Two important functions in salt.c are S_Trial & S_Shuffle.
The S_Trial function does one experiment. It initializes the two containers, moves a pinch from the salt to the pepper, shakes the pepper (shuffles it), then moves a pinch back to the salt. It is the place to look for errors in my understanding of the riddle.
The S_Shuffle function randomizes the order of the elements in an array. If I shuffled the arrays incorrectly, the results will be incorrect. One coworker said this shuffle function was wrong, but a friend is a doctor of statistics, & he said it was right.
There is a bug, too. The program uses an asterisk (*) to mark the trials that had differing final concentrations. It compares the concentrations, but they are floating point numbers obtained from the S_Rate function, so round-off & other errors can happen. (I have seen them happen.) The program should instead compare the number of salt grains in the salt shaker to the number of pepper flakes in the pepper shaker. It could get those numbers from the S_Count function.
The three output files from when I ran ./go are online. They are out-010.txt, out-100.txt, & out-500.txt.
Each of those files has 1,000 trials for containers that contain 1,000 grains of salt (or flecks or pepper), but each output file is for a unique pinch size. The first is for pinches of size 10. The second, for pinches of size 100. The third, for pinches of size 500, which is half of the container size.
To analyze the run, use ``grep
\* |wc -l'' on
each of the output files. (You'll need to pipe the output
file through the grep, or you'll need to name the
output file as the second argument to grep.) The
number you'll see is the number of trials in that output
file that did not result in a salt-to-pepper concentration
in the salt shaker that was equal to the pepper-to-salt
concentration in the pepper shaker. Since you know the
number of trials in each file (1,000), & each file is for a
unique pinch size, it's easy to compute the rate of unequal
concentrations for the pinch size. I've done that & put
the results in Table 1.
Because the rate of occurences of trials with unequal final concentrations is so low (from 1 percent to 38 percent, & that is possibly with some falsely marked final concentrations), I suspect the answer to the riddle is that the final concentrations are the same.
Gene Michael Stover 2008-04-20