Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Parallel

Jam Session


April, 2005: Jam Session

Solution to March Dr. Ecco

Solution to "Grab Bag," DDJ, March 2005.

1. Yes. Player A can force a win. Here is how:
Player A: 5
Player B: 0 (forced; grabs 5) Player A: 3 (grabs 3)
Player B: 1 (forced; grabs 4)
Player A: 1 (grabs 1 and 2)
2. Player B wins when n=1 and n=3, and there is a draw when n=2 (obvious cases). A can force a draw when n=4 and n=6, although A might lose if he plays badly. When n is 5 or at least 7, the first player (player A) can always force a win by playing this series of numbers: n, n-2, n-(2+3), n-(2+3+4),..., but he should depart from this strategy once he can grab all the remaining numbers. This strategy forces B to play 0, then 1, then 2, etc., and A grabs more and more. This works for any even or odd number. Consider n=11:
Player A: 11 (first move, grabs nothing)
Player B: 0 (forced; grabs 11) (Bgrab={11})
Player A: 9 (grabs 9) (Agrab={9})
Player B: 1 (forced; grabs 10) (Bgrab={11,10})
Player A: 6 (grabs 6 and 7) (Agrab={9,6,7})
Player B: 2 (forced; grabs 8) (Bgrab={11,10,8})
Player A: 2 (grabs 2, 3, and 4)(Agrab={9,6,7,2,3,4})
Player B: 3 (forced; grabs 5) (Bgrab={11,10,8,5}) FINAL, with four numbers grabbed
Player A: 0 (grabs the rest, 1) (Agrab={9,6,7,2,3,4,1}) FINAL, with seven numbers grabbed
3. The winning situations remain the same, but the strategy changes a little. That is, B still wins for n=1 and n=3, there is a draw for n=2, A can force a draw for n=4 and n=6, and A can force a win for n=5 and for n=7 or greater.
The strategy is similar, but A will follow this series when seeding: (-n)+1, (-n)+1+2, (-n)+1+2+3, (-n)+1+2+3+4... As before, A will depart from this strategy when able to grab all the remaining numbers. This will force B to seed the series n, n-1, n-2, n-3..., playing forced as before. Note that A can block the game by seeding -n in the first turn or by following this strategy and then grabbing the lowest nongrabbed number, but then A would lose.
Example with n=5
A seeds -4 and grabs nothing.
B seeds 5 (forced) and grabs 1
A seeds -2 and grabs 3
B seeds 4 (forced) and grabs 2
A seeds 0 and grabs 5 and 4.
A wins with three grabbed numbers while B grabbed 2.

Cristian Richart and Tomas Rokicki contributed to these solutions. Cristian found the solution to question 3 and proved that in the setting of the second question, it's always possible to grab a number if there are ungrabbed ones available after the first move.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.