A Random Matching Problem

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description


A clueless student faced a pop quiz - a list of 24 Presidents of the 19th century and another list of their terms of office, but scrambled. The object was t match the President with his term. He had to guess every time. On average, how many terms would he guess correctly?

Create a  program that simulates the quiz results by checking scores for a large number of random matching trials.

Background & Techniques

This problem was published by Marilyn vos Savant in her "Ask Marilyn" column in Parade magazine of July 25, 2004.   I couldn't figure out how to solve it analytically, so decided to resort to a simple program to generate test data. 

It should make an excellent Beginners program,  It took less than 40 lines of Delphi code to create it.  That included a loop that  generate sets of  numbers, a procedure to shuffle them to randomize the lists, and code to count how many are in the correct place and compute the average.   With enough code left over to use Delphi components to:

bulletlet the user select how many samples are in each trial (TSpinEdit), 
bulletwhether to display some of the detailed results (TCheckbox
bulletand  how many trials to run in each test (TRadiogroup)..

Enjoy!  

 Running/Exploring the Program 

bulletBrowse source extract
bullet Download source
bulletDownload  executable

Suggestions for Further Explorations

There is no doubt some analytical proof of the experimental results obtained here - I just don't know where to find it.  If you do, please  let me know,
Some of the trial results have no correct matches.  These are called "derangements".  It's an interesting fact that the number of trial results that will be derangements approaches n!/e  (where e =  the exponential constant, 2.718... ) as n gets larger.  Since the number of permutations of n things is n!, the fraction of outcome that will be derangements will approach  (n!/e)/n! = 1/e or about 37% as n increases.    See my Derangements page for more info.

 

Original Date: July 27, 2004 

Modified: July 29, 2017

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.