Empirical Lab Repository

Title: Simulation and the Marble Jar Puzzle

Author: Dave Reed, Creighton University, davereed@creighton.edu

Possible Courses: CS1

Empirical Concepts Introduced: simulation, data analysis

Computer Science Concepts Used: class use, data abstraction, loops, conditionals

Summary: This assignment involves writing a program to help solve a puzzle. The puzzle involves repeatedly drawing marbles out of a jar and selectively replacing marbles based on the combination drawn. While some students may be able to predict the outcome of the puzzle sequence by logic alone, most require additional data to see the pattern. To complete the assignment, the student will write a program that simulates repeated marble drawings, using a provided MarbleJar class that abstracts out the operations on a jar (drawing a marble, replacing a marble, and determining if empty). Using only these operations, the simulation program must perform and display the sequence of steps leading to a solution. Students are then asked to permorm repeated simulations and analyze the data in order to see the overall pattern and solve the puzzle.

The simulation is a relatively simple program, but it does emphasize the use of programs for analyzing complex data and the use of data abstraction via the MarbleJar class. Since the number of marbles is private data in the class, the student's program must use only the provided methods for manipulating the jar.

Variations: Numerous other puzzle can be similarly assigned using the MarbleJar class. For example, a simpler puzzle is the following: Given a jar with N marbles of each color (for arbitrary N), what are the odds of reaching into the jar and pulling out two marbles of the same color? Is it 50%? More than 50%? Less than 50%.