06.03.2017 Views

Mathematics for Computer Science

e9ck2Ar

e9ck2Ar

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

“mcs” — 2017/3/3 — 11:21 — page 184 — #192<br />

184<br />

Chapter 6<br />

State Machines<br />

because, taking XOR’s down the columns, we have<br />

0 0 1 0 (binary rep of 2)<br />

0 1 1 1 (binary rep of 7)<br />

1 0 0 1 (binary rep of 9)<br />

1 1 0 0 (binary rep of 12)<br />

This is the same as doing binary addition of the numbers, but throwing away the<br />

carries (see Problem 3.6).<br />

The XOR of the numbers of stones in the piles is called their Nim sum. In this<br />

problem we will verify that if the Nim sum is not zero on a player’s turn, then the<br />

player has a winning strategy. For example, if the game starts with five piles of<br />

equal size, then the first player has a winning strategy, but if the game starts with<br />

four equal-size piles, then the second player can <strong>for</strong>ce a win.<br />

(a) Prove that if the Nim sum of the piles is zero, then any one move will leave a<br />

nonzero Nim sum.<br />

(b) Prove that if there is a pile with more stones than the Nim sum of all the other<br />

piles, then there is a move that makes the Nim sum equal to zero.<br />

(c) Prove that if the Nim sum is not zero, then one of the piles is bigger than the<br />

Nim sum of the all the other piles.<br />

Hint: Notice that the largest pile may not be the one that is bigger than the Nim<br />

sum of the others; three piles of sizes 2,2,1 is an example.<br />

(d) Conclude that if the game begins with a nonzero Nim sum, then the first player<br />

has a winning strategy.<br />

Hint: Describe a preserved invariant that the first player can maintain.<br />

(e) (Extra credit) Nim is sometimes played with winners and losers reversed, that<br />

is, the person who takes the last stone loses. This is called the misère version of the<br />

game. Use ideas from the winning strategy above <strong>for</strong> regular play to find one <strong>for</strong><br />

misère play.<br />

Class Problems<br />

Problem 6.8.<br />

In this problem you will establish a basic property of a puzzle toy called the Fifteen<br />

Puzzle using the method of invariants. The Fifteen Puzzle consists of sliding square<br />

tiles numbered 1; : : : ; 15 held in a 4 4 frame with one empty square. Any tile<br />

adjacent to the empty square can slide into it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!