Click to See Complete Forum and Search --> : Help Please, Bell Curve


April 13th, 1999, 12:17 AM
How can we generate the Bell curve without doing any fancy math? The trick is to simulate events that have this distribution and we simply count the occurences of certain events.

Your task: You've probably seen those games where you can drop a coin on an "array" of pegs and if you are lucky, it ends up in the right spot at the bottom. Assume it looks as follows.

O One of the balls

xxx
xxx

xxx xxx
xxx xxx
The pegs
xxx xxx xxx
xxx xxx xxx

xxx xxx xxx xxx
xxx xxx xxx xxx

| | | | |
| | | | | The buckets
| | | | |
+-----+-----+-----+-----+
Each of the x-blocks is a peg. The balls (or coins) are dropped on the top-most peg. A ball always drops off a peg with the same probability for both sides. That is, whenever a ball drops on a peg it will keep dropping either on the left side or the right side of the peg until it drops into a bucket where it stays.
If you draw a bar graph representing the number of balls in the buckets you will get a, more or less symmetric, bell curve, e.g., like this.

***
*** ***
*** ***
*** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** ***
Your task is to write a program that simulates above process and prints out the bar chart. Your simulation must have n buckets where n is a integer constant. Set this constant to 8. (If you change the constant nothing should have to be chnaged in your program.) You program must ask the user how many balls it should simulate before displaying the result. Allow up to 50,000 balls.
Your program must allow to run as many simulations as the user wants, i.e., the program mustn't automatically exit after a simulation. For instance, you can ask for the number of balls to drop where 0 balls means stop the simulations.