high_card_parfor


high_card_parfor, a MATLAB code which uses the parfor() statement to compute in parallel the statistics for a card game in which you are required to guess the location of the highest card.

The rules for this game are as follows. You are given a deck of DECK_SIZE cards.

Your goal is to select the high card. For convenience, we can assume the cards are a permutation of the integers from 1 to DECK_SIZE, but in fact the user mustn't see such values or else it's obvious which is the largest card. (For a truly difficult problem, we'd have to work harder to disguise the range of values and the likely distribution!)

Your choice is made under the following rules: You may turn over one card at a time. When a card is turned over, you may declare that to be your choice, or else turn over another card. If you have not chosen a card by the end, then your choice is the final card.

If you have no idea what to do, and simply decide in advance to pick a card "at random", that is, for example, you decide to pick the 15th card before having seen any cards, then your probability of winning is 1/DECK_SIZE.

The question is, can you do better than that?

A good strategy is as follows: always look at the first SKIP_NUM cards without choosing them. Then choose the very next card you encounter that is larger than the cards you skipped.

Now the question is, is there an optimal value of SKIP_NUM for a given DECK_SIZE? One way to find an approximate answer is to choose DECK_SIZE, and then, for each value of SKIP_NUM, play 1000 games, and keep track of how often you are right.

This program demonstrates how such a computation can be done in parallel using the PARFOR command.

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

high_card_parfor is available in a MATLAB version.

Related Data and Programs:

high_card_parfor_test

collatz_parfor, a MATLAB code which seeks the maximum Collatz sequence between 1 and N, running in parallel using the parfor() command.

heated_plate_parfor, a MATLAB code which solves the steady (time independent) heat equation in a 2D rectangular region, using parfor() to run in parallel.

hello_parfor, a MATLAB code which prints out "Hello, world!" multiple times, using parfor() for parallel execution.

high_card_parfor, a MATLAB code which uses the parfor() statement to compute in parallel the statistics for a card game in which you are required to guess the location of the highest card.

matrix_assemble_parfor, a MATLAB code which uses parfor() for parallel execution to assemble the Hilbert matrix in a parallel loop.

md_parfor, a MATLAB code which carries out a molecular dynamics simulation, running in parallel using the parfor() feature.

ode_sweep_parfor, a MATLAB code which uses parfor() to parallelize the computation of a grid of solutions to a parameterized system of ordinary differential equations (ODE).

prime_parfor, a MATLAB code which counts the number of primes between 1 and N; running in parallel using the parfor() feature.

quad_parfor, a MATLAB code which estimates an integral using quadrature; running in parallel using the parfor() feature.

satisfy_parfor, a MATLAB code which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, running in parallel using the parfor() feature.

sparse_parfor, a MATLAB code which demonstrates how a sparse matrix can be constructed by evaluating individual blocks in parallel with the parfor() command, and then assembled (on a single processor) using the sparse() command.

Reference:

Source Code:


Last revised on 17 December 2023.