Saturday, November 9, 2013

How to interpret probability problems

In The Irksome Tuesday Boy Problem, Rob Eastaway complains of ambiguity in Gary Foshee's infamous puzzle, which asks: "I have two children, (at least) one of whom is a boy born on a Tuesday - what is the probability that both children are boys?"

I don't get the controversy over this. There's no ambiguity. These problems are meant to be thought of as repeated experiments, like surveys. We want to determine P(2 boys | two children at least one of which is a boy born on Tuesday). So this one becomes:

  • Pick a family at random
  • "Hello, sir/madam, do you by chance have exactly two children, at least one of which was a boy born on Tuesday?"
  • If they answer "no", then the interview ends immediately.
  • Otherwise, ask: "Do you have two boys?"
  • If "yes", record this call as a "hit"
  • if "no", record this call as a "miss"

After doing lots of these surveys, let h be the number of hits and let m be the number of misses. The desired probability is then h/(m+h).

If the answer depends on some reasonable assumption that is not explicitly stated in the problem, just calculate the answer based on that assumption and make it explicit it to your answer. Example: "The answer is 13/27, provided that the probability of a newborn being a boy is 1/2 and the probability of being born on Tuesday is 1/7."

Monday, October 28, 2013

The Exponential Lottery Puzzle

In this note, I will pose a puzzle about a lottery involving an exponential number of people. It is my version of a probability paradox called "The Shooting Room", which was invented by John A. Leslie in connection with the Doomsday Argument. I will first explain the rules of the lottery and ask whether you should buy a ticket. I will then explain two different ways of thinking about the problem and ask which, if either, is correct.

First, assume that every person is assigned a unique number at birth which doesn't change throughout the person's lifetime. We'll call this number the person's SSN (social security number). Assume that every person knows his/her own SSN.

Assume that the population grows without bound; that is, there's no specific limit to how large the population can grow. (Let's suppose that humans have become spacefaring and spread out throughout the universe, while still managing to maintain to assign unique SSNs to everyone.)

The lottery has 6 phases:

  1. The lottery commission secretly rolls a fair pair of 6-sided dice until they come up snake eyes (probability 1/36.) Let R be the number of rolls it took, including the final snake-eyes. If snake eyes are never rolled, then the lottery never starts.
  2. The lottery commission waits until the population is at least 10^R (10 to the power R).
  3. The lottery commission makes a list of every person alive in order from lowest SSN to highest.
  4. The lottery commission informs the first 10^R people on the list that they are eligible to play.
  5. Each eligible player now decides whether to buy a single ticket. This decision must be made in isolation; players may not talk about the lottery. A ticket costs $1.
  6. The first 10^(R-1) people on the list are potential winners. The lottery commission pays $2 to every potential winner who bought a ticket.

Question: Suppose you have SSN 5055305732 (or whatever), you know the rules of the lottery, and you have been notified that you are eligible to play. Should you buy a ticket? What is the expected value?

Here are two ways of thinking about the problem.

On the one hand, (number of potential winners) / (number of people eligible to play) = 10%. Thus, only 10% of the people who are eligible to buy a ticket would be winners if they did so. So you shouldn't buy a ticket.

On the other hand, you effectively became eligible to play on one of the R dice rolls: the first 10 people on the list were automatically eligible, then 90 more people became eligible on the first roll if it wasn't snake eyes, then 900 more people became eligible on the second roll if it also wasn't snake eyes, and so on. At each roll, the probability of a later group of people, approximately 10x larger, becoming eligible is 35/36. If this happens, the people who were already eligible will be in the first 10%. Thus, the probability that you are a potential winner, given that you are eligible to play, is about 35/36. So you should buy a ticket.

Which line of reasoning, if either, is correct?

Tuesday, June 18, 2013

How to Play Sprouts with Playing Cards

It's not much fun to play sprouts with playing cards, but it is possible. Why would anyone want to do such a thing? Maybe it will be easier to analyze the game or more straightforward to implement it on a computer this way. Maybe you're fresh out of pens and paper.

To play a game with N initial spots, you'll need three identical decks of playing cards with at least 3N+1 distinct cards in each deck. This way each card will have exactly two identical "twins". (Actually, the cards are incidental; integers will suffice. This document is really about how to generate legal moves and update a position represented in Dan Hoey's boundary-list notation.) In the rules below, we'll assume you've combined the three decks into one large deck. You will also need a flat space for at least 2N+1 rows of cards. A large wooden table will do nicely. Each row will contain zero or more stacks of cards, and each stack will contain one or more cards.

To "cut" a stack of cards means the usual thing: remove one or more cards from the top of the stack (preserving order) and put them under the remaining cards in the stack. Here, the player may examine the stack and cut it in any place they choose.

To "play" a card, remove it from the deck and place it in the specified location.

Initial position and play

The initial position consists of N different cards, each in an isolated stack, all in the same row. Players take turns moving. There are two kinds of moves, joining moves and dividing moves. On his turn, a player must execute either a legal joining move or a legal dividing move, but not both in the same turn. Under the normal play convention, the last player wins. Under the misere play convention, the last player loses.

Joining moves

A joining move combines two stacks in the same row. If any step of the move is not possible, the move is illegal.
  1. Choose two different nonempty stacks A and B in the same row. Optionally, cut stack A. Optionally, cut stack B.
  2. If A has more than one card, then play a twin of the top card to the bottom of the stack.
  3. If B has more than one card, then play a twin of the top card to the bottom of the stack.
  4. From the deck, remove two identical cards that are not already on the table. Place one on top of A, and one on top of B.
  5. Place A on top of B.

Dividing moves

A dividing move divides a stack into two stacks, one of which is placed in a new row. One or more stacks from the original row may be moved to the new row. If any step of the move is not possible, the move is illegal.
  1. Choose a nonempty stack. Optionally, cut it.
  2. Play a twin of the top card to the bottom of the stack.
  3. Remove one or more cards -- but not all of them -- from the top of the stack and place them in a new row.
  4. If the original stack or the new stack has more than one card, then play a twin of the the bottom card of the new stack to the top of the original stack.
  5. From the deck, remove two identical cards that are not already on the table. Place one on top of the new stack, and one on top of the original stack.
  6. Optionally, move one or more stacks -- other than the original stack — from the original row to the new row.

Example game

Consider the following game of 5 moves (in WGOSA notation): 2+ 1(3)2 1(4)2 1(5)4 2(6)3 (see images below)

Here's how that game would be played with cards. To represent the position in text, we will use the following conventions: A stack of cards is written in order from top card to bottom, with a comma between each card. A semicolon separates each stack from adjacent stacks in the same row. A slash separates each row from its neighbors. (This is the notation used by Dan Hoey in his paper on sprouts notation.)

(2)initial position:
  • 1;2
(3)joining move:
  1. 1;2
  2. (skipped)
  3. (skipped)
  4. 1,3;2,3
  5. 1,3,2,3
(4)dividing move:
  1. 1,3,2,3
  2. 1,3,2,3,1
  3. 1,3,2/3,1
  4. 1,3,2/2,3,1
  5. 4,1,3,2/4,2,3,1
  6. (skipped)
(5)dividing move:
  1. 1,3,2,4/4,2,3,1
  2. 1,3,2,4,1/4,2,3,1
  3. 1,3,2,4/1/4,2,3,1
  4. 1,3,2,4/4,1/4,2,3,1
  5. 5,1,3,2,4/5,4,1/4,2,3,1
  6. (skipped)
(6)dividing move:
  1. 5,1,3,2,4/5,4,1/2,3,1,4
  2. 5,1,3,2,4/5,4,1/2,3,1,4,2
  3. 5,1,3,2,4/5,4,1/2,3/1,4,2
  4. 5,1,3,2,4/5,4,1/2,3/3,1,4,2
  5. 5,1,3,2,4/5,4,1/6,2,3/6,3,1,4,2
  6. (skipped)

Analogy with graph

We have represented a plane graph using rows of stacks of cards.
Playing card termGraph theory term
cardoccurrence of vertex in boundary
stackleft-hand walk of vertices on boundary
rowface, i.e. set of boundaries
tableplane graph, i.e. set of faces

Credits

Author: Josh Jordan
Initially published at http://www.wgosa.org/playingcardssprouts.htm

This document builds upon the sprouts notation system devised by Dan Hoey.

Tuesday, April 23, 2013

John Graham-Cunning's Minimum Coin Problems

In The Minimum Coin Problem, John Graham-Cunning poses the following problems:
  1. Given a pile of coins and a target amount, find a way to pay exactly that amount using the maximum number of coins from the pile.
  2. Given a pile of coins and a target amount, find a way to pay at least that amount using the maximum number of coins from the pile, such that removing any coin from the payment yields an amount that is less than the target amount.
  3. Given a pile of coins — each type of coin having a given weight — and a target amount, find a way to pay at least that amount using the maximum weight of coins from the pile, such that removing any coin from the payment yields an amount that is less than the target amount.
These can each be posed as integer programming problems and solved with a solver such as GLPK. Here is a solution to problem 1, a solution to problem 2, and a solution to problem 3.

Tuesday, September 20, 2011

Open-source answer set solver vs Fico Xpress Optimization Suite

Fico's Xpress Optimization Suite is used by American Airlines, Avis, Honeywell, and the NFL to solve industrial-sized problems in operations research. I was reading one of Fico's white papers, Hybrid MIP/CP solving with Xpress-Optimizer and Xpress-Kalis (May, 2009), when I came across the following statement about a problem in machine assignment and sequencing.
"It is possible to implement this problem entirely either with Xpress-Optimizer or wit Xpress-Kalis. However, already for this three machines – 12 jobs instance the problem is extremely hard for either technique on its own." [Section 3.4 ("Results"), page 19, italics mine]
Fico approached this dilemma by creating a hybrid of the solutions for both solvers. The code looked complicated, though, and the problem itself didn't seem that hard. I wanted to see if I was missing something, so I wrote it up in the language of the open-source answer-set solver Clingo.
According to the paper, "Optimality is proven within a few seconds on a Pentium IV PC." It takes clingo 3.5 seconds on an Athlon 64 (a similar CPU) to find the same solution. The Xpress-Optimizer+Xpress-Kalis hybrid solution is about 220 lines of code (LOC), while the Clingo solution is about 20 LOC. (*)

According to Section 4 (Summary), "Hybrid solution algorithms need to be developed, implemented, and tested on a case-by-case basis, meaning a considerable investment in terms of development effort and requiring a good understanding of the solution methods and solvers involved."

Indeed. Or you could just use Clingo.


(*)  When counting LOC, I ignored lines that consisted only of
  • comments,
  • code for displaying output,
  • code for specifying the problem parameters (there were none of these in the Xpress solution), or
  • code for configuring the solver (there were none of these in the clingo solution).




Wednesday, March 2, 2011

How I Beat the World Champion at Sprouts

With the help of my program Aunt Beast, I won the World Game of Sprouts Association 2010-2011 Tournament in January, 2011. The human world champion requested a follow-up match, billed by WGOSA as the “2011 Clash of the Titans” . As of March, 2011, the match is still ongoing, but in mid-February, I won the first game. Here’s how I did it.

Update I: I also won game 2. Here's my analysis.
Update II: I lost game 3, but won game 4. Analysis forthcoming.
Update III: I won game 5 and lost game 6, so I won the match. WGOSA has a write-up.

Tuesday, May 4, 2010

FlowerFinder by William Waite

FlowerFinder is a puzzle with only 6 pieces but a rather large state space. One objective is to place them into the frame in two layers so that in each of the 9 circles, exactly 3 petals are visible.

Each circle can be one of four types, which we will call "top-left", "top-right", "bottom-left", and "bottom-right". We will assign each piece a number from 1 to 6. Each piece is defined as a sequence of three circle types. For example, in the photo, the circles in piece 1, from top to bottom, are of type down-left, up-right, and up-left. Before a piece is placed in the frame, it can (optionally) be flipped horizontally and (optionally) be flipped vertically. We define locations 1,2,3 as the bottom of the frame from left to right, and locations 4,5,6 as the locations in the top of the frame, perpendicular to 1,2,3. Without loss of generality, we can assume that piece 1 is in location 1 or 2, and is not flipped horizontally or vertically. Finally, we require that the petals in each circle in the top row align with the petals in the corresponding circle in the bottom row.

$ clingo 0 flowerfinder.lp

Answer: 1
fliph(3) fliph(5) fliph(6) flipv(2) flipv(3) pieceloc(1,1) pieceloc(2,2) pieceloc(3,3) pieceloc(4,6) pieceloc(5,4) pieceloc(6,5)
SATISFIABLE

Models      : 1
Time        : 0.020
  Prepare   : 0.010
  Prepro.   : 0.000
  Solving   : 0.010

So the unique solution is to horizontally flip pieces 3, 5, and 6, vertically flip 2 and 3, put the pieces in the specified locations.

How large is the state space? The first piece is in one of two locations, and there are 5! ways to place the remaining pieces, 25 ways to represent the "horizontally flipped" state of those pieces, and 25 ways to represent the "vertically flipped" state of each of those pieces. Finally, the top layer can either be perpendicular to the bottom layer or not. By this reasoning, there are 5! · 25 · 25 · 2 = 257760 different ways to place the 6 pieces in the frame.

Followers

Contributors