15
Sum Games - The MEX Function AE1APS Algorithmic Problem Solving John Drake

AE1APS Algorithmic Problem Solving John Drake. Coursework 3 due on Thursday at 1pm (i.e. before the start of the tutorial). Submit either hard-copy

Embed Size (px)

Citation preview

Page 1: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Sum Games -The MEX Function

AE1APS Algorithmic Problem SolvingJohn Drake

Page 2: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Coursework 3 due on Thursday at 1pm (i.e. before the start of the tutorial).

Submit either hard-copy (including name/student number), or e-mail soft-copy to me.

Normal university regulations apply to late submissions

Please let me know if you have any problems! Office SEB325 [email protected]

Notice

Page 3: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Consider the sum of two games

Page 4: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

The position in a given sum game is (l, r). A move affects one component (i.e one

game) An assignment can either be l := l’ or r :=r’ (i.e. the left or right component is affected)

Define two functions L and R on the left and right positions such that; (l, r) is a losing position exactly when L(l) =

R(r)

Symmetry in sum games

Page 5: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

L and R must have equal values on end positions

All moves from a losing position should result in a winning position satisfying

L(l) != R(r)

Applying the winning strategy from a winning position, should result in a losing position

Analysis

Page 6: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

We require that:

For end positions L(l) = R(r) = 0

For every l’ such that there is a move from l to l’ - L(l) != L(l’)

For any number m < R(r), it is possible to move from r to r’ such that R(r’) = m (similar for left).

Analysis

Page 7: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Fortunately for us such a function exists

The MEX function, short for “minimal excludant”, satisfies these conditions and is therefore used as the functions L and R

Mex Function

Page 8: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Let p be a position in a game. The mex value of p (mex(p)), is defined as the smallest natural number, n, such that

There is no move in the game from p to position q satisfying mex(q) = n

For m < n, there is a move from p to q satisfying mex(q) = m.

This is a recursive definition.

Definition of Mex Function

Page 9: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Informally, mex(p) is the minimum number that is excluded from the mex numbers of positions q to which a move can be made from p (i.e. q is a successor of p).

Definition of Mex Function

Page 10: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

The graphs do not have regular structure, so the mex numbers must be calculated by hand

End positions have a mex number of 0 A mex number can be give to a node when

all its successors have been assigned a mex number

The number is the smallest number that is not included in the mex numbers of its successors

Using the MEX function

Page 11: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Calculating the Mex Function

Page 12: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Calculating the Mex Function

Page 13: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Suppose we start with “ok” (o,k) as our position This is a winning position because the mex

numbers are different The winning strategy is to move the right graph to

node i which has the same mex number as “O” i.e. we are restoring the balance (R(r ) = L(l ))

The opponent will then disrupt the balance (making this an inequality)

The first player the repeats the strategy of making the mex numbers equal, moving in the game with the highest mex number, until the opponent can move no further

Playing the game

Page 14: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Note that due to the lack of structure, the mex number of the 15 left and 11 right positions were calculated individually

In total we only did 15+11 (=24) calculations, and not 15*11 (=165) calculations

Lack of Structure

Page 15: AE1APS Algorithmic Problem Solving John Drake.  Coursework 3 due on Thursday at 1pm  (i.e. before the start of the tutorial).  Submit either hard-copy

Past Exam Question – 2011/12

b)

a)

b)

(15)

(20)