Statistics puzzle i05244c

Bradley K. Sherman bks at alfa.berkeley.edu
Thu Jun 16 00:02:08 EST 1994


In article <2tfv1n$t8d at cville-srv.wam.umd.edu> bcohen at wam.umd.edu (Brad Cohen) writes:
>
>Martin Gardner says that new mathematical puzzles are very
>difficult to devise.  What do you think of this one?

Not a lot, what's the bid?  The syntax leaves a lot to be
desired.  Here's a simulator for the problem that indicates
that the probability is about .48.  Note that I have included
the original problem wording in the main() routine.

    --bks

/* -----------------------8< cut here for pesky.c >8------------*/
/*
 *	pesky.c
 *
 *	to compile:
 *		cc -o pesky pesky.c
 *	to run:
 *		pesky
 *	Author:
 *		Bradley K. Sherman (bks at s27w007.pswfs.gov)
 *		Dendrome project, Institute of Forest Genetics
 *		P.O. Box 245, Berkeley, CA, 94701
 *	Date:
 *		15 June 94
 *
 */
#include <stdio.h>

#define WEST  0
#define NORTH 1
#define EAST  2
#define SOUTH 3

#define ACE_D 14
#define ACE_H 27

int Deal[52] = {
 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52
};

main()
{
	long int count = 0;
	long int west_has_ace = 0;

	srandom(getpid());

	while( 1 ) {
		shuffle();

		/*
		 * A slightly less-than-honest bridge player (south)
		 * caught a glimpse of a card dealt to her opponent
                 * on the left (west) - it was a red ace (she could
                 * not tell which suit).
                 */
		if ( ! dealt(WEST, ACE_D)  &&  ! dealt(WEST, ACE_H) )
			continue; /* No red ace for WEST */

		/*
		 * This opponent -- west -- opens the game by playing
		 * the ace of diamonds.
		 */
		if ( ! dealt(WEST, ACE_D ) )
			continue; /* No ace diamonds for WEST */
		/*
		 * South sees that neither she nor the revealed cards
		 * of north have the ace of hearts, which must be in
		 * either east's hand or west's hand.
 		 */
		if ( dealt( SOUTH, ACE_H )  ||  dealt( NORTH, ACE_H ) )
			continue; /* S or N have the heart ace */

		/*
		 * What is the probability now that west has the
		 * ace of hearts?
		 */
		++count; /* Start */
		if ( dealt( WEST, ACE_H ) )
			++west_has_ace;
		if ( count % 100 == 0 ) {
			printf( "has heart ace/deals = %d/%d = %g\n",
				west_has_ace, count,
				(double)west_has_ace/(double)count);
		}
	}
}

/* return 1 if player has card, 0 otherwise */
dealt( player, card )
{
	int i, low, high;

	switch(player){
	case WEST  : low = 0;  high = 12; break;
	case NORTH : low = 13; high = 25; break;
	case EAST  : low = 26; high = 38; break;
	case SOUTH : low = 39; high = 51; break;
	}

	for ( i = low; i <= high; i++ )
		if ( Deal[i] == card )
			return 1;
	return 0;
}

/* 
 * Adapted from Knuth Vol 2. Algorithm P, p 139, 2nd ed.
 */
shuffle()
{
	int j, k, tmp;
	for ( j = 52; j > 0; j-- ) {
		k = random() % j ; /* 0 <= k < 52 */
		tmp = Deal[k]; /* swap */
		Deal[k] = Deal[j - 1];
		Deal[j - 1] = tmp;
	}
}
/* -----------------------8< cut here for pesky.c >8------------*/




More information about the Bioforum mailing list