**2.4 Left/Right Ends**

Alice and Beth play a game of removing numbers from a line of 2 N numbers. Each player collects a number on her turn from one of the ends (a player may choose different ends in different turns). The removal of numbers ends when the line is empty. At this stage, each player sums the numbers she collected. Devise a strategy for Alice (the first player), which guarantees that her sum will be either larger than or equal to Beth's sum.

Many problem solvers follow an operative approach that focuses on *local* ends of the given line. They notice right away that it may be wrong to select the end number that is larger than the other end, since the inner value next to that chosen end may be large (and will become available to the opponent). They suggest looking at the *delta* of each end, which is the difference between the end number and the number next to it. They offer to select the end number from the end whose delta is larger; that is, select

#### **Figure 3.**

*A game line of eight numbers.*

the better "gained minus exposed." We illustrate this idea with the line of numbers in **Figure 3**.

Alice will compute the two "end deltas"—7–8 on the left end and 6–4 on the right end. Since −1 is smaller than 2, Alice will take the 6 from the right end. Beth will take any end number that she wishes, and Alice will calculate again the new "end deltas" in the same way for her next choice. And so on.

At first glance, this local strategy seems promising and leads to a win for many line examples. (Does it lead to a win in the line below?) However, its local focus on the line ends, and not on the whole line, may lead to a loss. Falsifying examples are not immediate, but one may find lines of length smaller than 10 for which this strategy will fail. Some problem solvers do not notice the latter and "argue" correctness with

partial, heuristic argumentation. Others who do notice the difficulty try to "patch" it in diverse unsuccessful ways.

One should seek a sound declarative observation on which to capitalize. The natural tendency may be to focus on the values of the given line numbers. But a creative, flexible thinking may lead to the examination of *locations* of the numbers in the original line. The line includes an even amount of numbers. This yields an illuminating observation when we look at the **parities of the locations of the original line**. (Half of the locations are odd, and half are even.)


We examine these observations with the line of numbers in **Figure 3**. If, for example, Alice will remove the 6, then Beth will have to choose between 7 and 4, which were originally in odd locations. Regardless of which number Beth will choose, Alice will receive a line whose ends were in locations of different parities in the original line.

At this point, a playing strategy can be devised for Alice. She may *force* a game in which she will collect all the numbers that are originally in the odd locations or all the numbers that are originally in the even locations. Thus, in the beginning of the game, she will see which sum is larger—that of the numbers in the odd locations or that of

#### **Figure 4.**

*Line numbers colored according to the parities of their locations.*

the numbers in the even locations—and decide accordingly. The numbers of these sums are illustrated in red and blue in **Figure 4**.

The creative aspect of this strategy stems from examining locations, *without* looking at the values in these locations (in the beginning of the analysis). This demonstrates the asset of turning to a declarative perspective, in trying to obtain an insight *into the problem*, prior to the development of any algorithmic solution.

Many problem solvers are "fixated" on values throughout their problem-solving process and miss this perspective. Such a phenomenon is typical of those who turn immediately to an operative perspective, seeking an algorithmic solution right away, without carefully analyzing first the problem at hand.

The above observations are specified in an **invariance** manner, in the sense that they relate to **every move** of a player, throughout the game. Invariance is a powerful means in both mathematics and computer science, for "capturing" properties of recurring states (e.g., [11]). As such, it is most relevant for games, as a means for characterizing recurring positions throughout a game. We shall see an additional example of invariance in the next games, when formulating a winning strategy that forces a sequence of losing positions on the loser of a game.

The displayed strategy involves **pre-processing**, which occurs here when the game data is provided and before making the first move. Pre-processing is a useful and powerful feature in algorithm design [11].

The presented strategy guarantees that Alice will not lose the game, but there may be initial lines for which she will end in a draw when she can actually win. A computational approach, employing dynamic programming [11], will yield a maximal sum for Alice in each game. The interested reader is welcome to program the latter. It will be based on computing the maximal sum that can be obtained by the winner in a separate game for *every* sub-sequence of the original line.

#### **2.5 State-space reduction**

In many games, the general state space may be very large. However, the winner may direct the game, so it will be played in a very particular path, and many legal states (positions) will be out of reach. The path will involve a limited number of winning and losing positions. One occurrence of this phenomenon may be reached by disabling the usage of game pieces. The following problem solving illustrates this phenomenon, with a variant of the game of domino.

#### **2.6 Domino line**

Alice and Beth play domino with a pile of N×(N + 1)/2 stones, of the pairs <1,1>, <1,2 > up to <N-1,N>, <N,N>. The order of the two integers in a stone does not matter; that is, the single stone <K,L > may be rotated and become <L,K>. Each player *sees* all the stones in the pile throughout the game. At the beginning of the game, Alice picks from the pile any stone that she wishes and starts a line of stones by putting the first stone. From this point on, each player picks a stone from the remaining pile and *lengthens the line*, to the left or to the right (as she wishes), by putting her chosen stone according to the domino rules (neighboring ends of adjacent stones match). **Figure 5** displays a possible game state after five moves. The game ends when there are no stones in the pile with which one can


#### **Figure 5.**

*A game state after five moves.*

lengthen the line. The player who makes the last move wins. Devise a strategy for winning the game.

At first glance, problem solvers get the impression that this is a simple game to analyze. Yet, many struggle, sometimes considerably. Some problem solvers seek a winning strategy by using all the game stones. Others try a table for keeping track of used stones. And some represent the game with a graph and try to devise an algorithm for expanding a path in the graph. All these attempts yield partial operational schemes, which are cumbersome and/or erroneous.

The solution of this game may be reached in two stages of declarative observations. A common theme in many games is an ordered reply to every opponent move. This was explicit in the first game that we presented, with the notion of pairing. This notion could be applied here if each domino stone was doubled. In such a case, Beth could win by responding to every move of Alice with a paired stone.

Unfortunately, we do not have such pairs of stones in our game. Yet, in a creative first step, we may temporarily simplify the game, by leaving out stones that may look more "problematic"—the "doubles" stones, of the form <K,K>. And we may create

pairs with **some** of the remaining stones, in an original way, according to the following observation.

• *In a game with no doubles, one may pair some of the stones, using the integers 1 and 2, such that for every X > 2, the two stones < 1,X > and < 2,X > will be a pair.*

This pairing does not involve all the stones of the game. But we may direct the game so that only stones with 1 or 2 will actually participate in the game. This can be done according to the following observation.

• *In a game with no doubles, if Alice will start the game by putting the stone < 1,2>, then Alice may* **force the game** *to be played only with stones of the form < 1,X > and < 2,X > (X > 2), as Alice may reply to Beth's stone with its paired stone.* **After every move** *of Alice, each end of the line will be either 1 or 2.*

**Figure 6.**

*The game state after three moves, of forcing only stones with 1, 2, or both.*

**Figure 6** displays a line of three stones reached after three moves according to the above idea. Alice started with the left-most <1,2 > stone, Beth put <2,4>, and Alice replied with <4,1 > − the stone paired with <2,4 >.

At this point, we may "return" the doubles to the game. The addition of the doubles may seem problematic at first glance, as doubles do not have paired stones. But with some flexibility, of using the idea of a "long stone," we may overcome this challenge.

• *In the original game, with doubles, it is possible to create a "***long stone***" from a sequence of three stones that will serve as the stone < 1,2 > in the previous observation. If Alice will start with the stone < 1,1>, Beth will follow with the stone < 1,Z>, and Alice will respond with the stone < Z,Z>; the sequence < 1,1 > <1,Z > <Z,Z > may be viewed as a "long <1,Z> stone," and from this point on, the integers 1 and Z will serve as 1 and 2 in the previous observation.*

**Figure 7** illustrates the above "long stone" idea, where the number 5 is Z. The above creative observation yields a winning strategy for Alice, in a game in which only stones with 1 and Z will be used.


**Figure 7.** *A "long" <1,5> stone.*

The strategy correctness is rather clear, based on the creative idea of the "long <1,Z> stone" and the notion of pairing. Notice that this winning strategy **narrows** the game considerably. It **forces** the game to be played with a small set of stones. The path in which the game is played **alternates between winning positions and losing positions**. In particular, Alice leads Beth in each of her moves to a losing position, which

is characterized by line ends that are either 1 or Z. This narrows considerably Beth's options of choosing a valid stone, and for any stone that she will choose, Alice has a reply. Notice the **invariance** feature of the line after each of Alice's moves.

The problem-solving process progressed gradually, through three observations, obtained from flexible, creative ideas. These ideas express **divergent thinking**. Although the end result is simple and clear, progress could not occur without such thinking. Problem solvers who are not invoking the notions of pairing and invariance and are less creative struggle here with unfruitful heuristic attempts.

#### **2.7 In spite of incomplete information**

Sometimes one may devise a strategy that is only based on the game information provided in the game specification. While the game information will be incomplete during the game, one may still win by knowing only the rules that the opponent obeys. This is illustrated with the following game.

#### **2.8 Wall of doors**

Alice and Beth play a game with a wall of N doors. The doors are numbered 1 to N. Alice walks along the wall and opens and closes doors. Beth moves behind the wall from door to door. Alice *does not know* Beth's location throughout the game. When the game starts, Beth stands behind one of the doors. Alice may open any door that she wishes in order to see if Beth is behind. If Beth is there, the game ends with Alice's win. Otherwise, Alice closes the door, and Beth moves to an *adjacent* door, on the right or left (as she chooses; though if she is near an end door, then she has only one choice). Alice does not see Beth's move. Then, Alice opens a door again, which can be the same door or any other door. The game continues for at most 5 N opening attempts. If Alice finds Beth, then she wins; otherwise Beth wins. Would you like to be Alice or Beth?

**Figure 8** displays a game state in which the red-hair Alice is about to open door 3.

#### **Figure 8.**

*A game state in which Alice is in front of door 3 and Beth is behind door 6.*

Beth is behind door 6. After Alice will realize that Beth is not behind door 3, Alice will close that door, and Beth will move to door 5 or door 7. Alice will then try to open any other door, or the same door, and the game will continue accordingly.

As we may see, Beth's location is hidden from Alice throughout the game, including the beginning. The question is whether Alice can always find Beth in spite of her limited information. Problem solvers attempt various operational methods for Alice. Many conjecture that Alice should start from one of the ends, move in one direction, and sometimes try to open doors twice (or more). Their attempts are usually not clearly phrased and not displayed with sound argumentation of correctness.

A declarative perspective may illuminate problem characteristics on which to capitalize. We present three observations, which are unfolded gradually, in trying to understand

#### *Problem Solving of Mathematical Games DOI: http://dx.doi.org/10.5772/intechopen.108520*

the occurrences that lead to opening a door behind which Beth is standing. The first observation is trivial. Yet in our experience, it is not that naturally invoked, as problem solvers are "busy" with operational ideas for Alice, rather than with observations.


The last assertion implies that if Alice will first open a door in one of the wall ends and then open every door on the way to the other end, then she will find Beth if their initial distance is even. However, this "one pass" will not end successfully if their initial distance is odd. The odd distance between them will be kept all along. The following observation offers a way to change the parity of the distance between them.

• *Opening a door twice in a row changes the parity of the distance between the girls.*

Thus, if Alice will reach the other end of the wall without finding Beth, she will infer that their initial distance was odd. Alice will open the end door twice and find Beth on her way back to the first door. All in all, Alice will not open more than 2 N + 1 doors.

The gradual declarative observations paved the way to the elegant solution. The underlying mathematical element was **parity of the distance** between the two girls. We may recall the relevance of parity (of locations) in the Left/Right Ends game. As in the previous games, here too one may formulate an invariant for describing and arguing about the correctness of the devised strategy.

#### **2.9 Natural number properties**

Many games involve natural numbers. One such game is the well-known game of Nim [1]. The winning strategies in these games capitalize on properties of numbers and involve the features of pairing and invariance. Some also relate to the notions of parity and/or symmetry. We display below three games with such features.

#### **2.10 Powers of 2**

Alice and Beth play a game with 10 piles of tokens. The first pile is with one (20 ) token, the second is with 2<sup>1</sup> tokens, the third is with 2<sup>2</sup> tokens, and so on. The largest pile contains 29 tokens. Each player, on her turn, selects 5 of the piles (as she wishes) and removes one token from each of the selected piles. The game ends when no move can be played (too few non-empty files). Devise a strategy for winning the game.

Problem solvers who turn to the operational approach in trying to devise a strategy experience difficulties with the sole token in the smallest pile. A declarative approach will first focus on patterns of powers of 2. The following basic property may be relevant.

**Figure 9.** *The smaller five piles of the ten piles.*

• *Every power of 2 is greater (by 1) than the sum of all the powers of 2 that are smaller.*

**Figure 9** displays the first five piles. One may visually notice the observation above about the relation between each pile and those on its left.

This property may be elegantly tied to our game, with the following observation.

• *The game will end when the 6 smallest piles will be emptied, and at this point, none of the 4 largest piles will be empty.*

The latter observation is justified by the recognition that even if each of the four largest piles will be selected in every move of the game, one token will still be removed from one of the six smaller piles. The observation yields a simple useful idea that addresses the difficulty that stems from the sole token in the smallest pile.

• *The 4 largest piles may be used as a "***bank***" from which tokens may be removed, in order to reach an invariant property with the 6 smaller piles.*

Alice may win the game by removing in her first move the single token of the smallest pile plus a token from each of the four largest piles and then keeping the following **invariant**.

• *The number of tokens in each of the 6 smaller piles will be even after each move (of Alice).*

Alice will keep the above invariant by duplicating each of Beth's moves. The amount of 0 tokens in each of the six smallest piles will be reached only by Alice. In retrospect, the simple property of powers of 2, plus the idea of using the larger piles as a "bank," paved the way to the winning strategy.

#### **2.11 Co-Primes**

Alice and Beth play a game with a line of N successive positive integers, N > 11, from K to K + N-1. Each player, on her turn, removes an integer from the line. After N-2 turns, two integers will remain. If these two integers are co-prime, then Alice wins; otherwise, Beth wins. For which initial sequence of integers will Alice win, and for which will Beth win? Devise a strategy for winning the game.

Upon approaching the problem, one may wonder whether the values of N and K are important. In our experience, quite a few problem solvers do not examine N and

#### *Problem Solving of Mathematical Games DOI: http://dx.doi.org/10.5772/intechopen.108520*

K at first glance, and seek a winning strategy for Alice, by focusing on removal of integers that have many divisors. They attempt some heuristic strategies but do not advance much. Meanwhile, some notice that every second integer in the initial line is an even number and change their initial train of thought, this time seeking a winning strategy for Beth.

The main theme in these hasty, heuristic attempts is their operational approach, based on intuitive, partial observations. The more competent problem solvers seek underlying characteristics. They first analyze the given problem and wonder about properties of co-primes. Obviously, a prime number is a co-prime with any other number. But it is unclear whether such a characteristic may be useful. It may be better to seek another co-prime characteristic. Further examination yields a simple and elegant observation.

#### • *Every two successive integers are co-primes.*

This observation implies a simple winning strategy for Alice when N is odd, which will be based on the following line pattern.

• *Every line of 2L successive integers may be divided into* **pairs** *of successive integers, which are co-primes.*

The latter pattern implies that for the case of odd N, Alice may divide the initial line into adjacent pairs of successive integers, except for the left (or right) end. She will first remove this end and then respond to each of Beth's moves by removing the integer paired with the one just removed by Beth.

So the problem is solved for the cases of an odd N, with the **pairing** feature. May this strategy be relevant also for the cases of an even N? Not quite. The player who plays first may not pair all the integers remaining after her first move. When N is even, the number of even integers in the line equals the number of odd integers. We notice the following.

• *Alice* **must** *remove an even integer in* each *of her (N/2)-1 moves.*

If Alice will not do so, Beth may lead the game to two even integers in the end. But if Alice will solely focus on the even numbers, Beth may leave two odd integers that are multiples of 3 if the initial line is long enough. What is long enough?

• *Every line of more than 11 successive integers includes at least two odd integers that are multiples of 3.*

Since the initial line length is larger than 11, Beth will win the game when N is even. All in all, the declarative perspective gradually paved the way to the winning strategies with a series of corresponding observations.

#### **2.12 Powers of primes**

Alice and Beth play a game with two piles of tokens. Each player, on her turn, removes from one of the piles a number of tokens that is a power of a prime (the power 0 is also legal). For example, from a pile of 15 tokens, one may remove in one turn any number of tokens apart from 6, 10, 12, 14, and 15. The game ends when both piles are empty. Devise a strategy for winning the game.

As with previous games, quite a few problem solvers attempt various operational ideas of removing tokens. Some recall a two-pile variant of the game of Nim and attempt symmetry, trying to equalize the amount of tokens in the piles. They realize that this idea may not be applied in some initial positions. Others focus on emptying one pile first (e.g., the smaller) and then proceeding to the second. They feel that their ideas lack rigor.

Gradual progress combined with declarative observations offers a fruitful and sound result. As a first step, we may solve the case of a single pile. Upon examining game scenarios with very small piles, we may notice the following.

• *In a game with a single pile, the amount of 6 tokens is the smallest amount from which the game will not end in one move, since 6 is the multiplication of two different primes. Thus, 6 is a losing position.*

Further examination of game scenarios with larger piles reveals that in a game with a single pile, the amounts of 12 and 18 are also losing positions (for the player who is about to play). A corresponding generalization may be observed. We specify it in two (equivalent) ways—with the indication of losing positions and with invariance.

• *In a game with a single pile, the losing positions are ones with token amounts that are multiples of 6. The winner should keep the following* **invariant***: after each of her moves, the amount of tokens in the pile will be a multiple of 6.*

The initial positions in which the number of tokens is not a multiple of 6 are winning positions, as in each of them the first to play may lead to the above invariant in one step. At this stage, we may move to the second step—the original game.

**Figure 10.** *Piles that cannot be equalized in one move.*

For some initial positions, it is impossible to equalize the amounts of tokens in the piles in one move. This is the case in the example of **Figure 10**, with piles of token amounts of 3 and 9.

Perhaps it is possible to obtain some variant of equal amounts. We noticed the importance of multiples of 6. With some flexible, creative thinking, we reach the following declarative observations related to the notion of remainder.

• *If the* remainders *of division by 6, of the token amounts in both piles, are equal, then the next move will yield different remainders, and the move that follows may yield equal remainders.*

• *In a game with two piles, the losing positions are ones in which the* remainders *of division by 6, of the token amounts in both piles, are equal. The winner should keep the following* **invariant***: after each of her moves, the remainders of division by 6, of the token amounts in both piles, will be equal.*

All in all, for the initial positions in which the difference between the amounts of tokens in the piles is not a multiple of 6, Alice will win. In all the other initial positions, Beth will win. The path to the final observation was gradual, and as with previous games, declarative observations and creativity paved the way.

### **3. Conclusion**

We illustrated the essential role of the declarative perspective in problem solving of mathematical games. This perspective leads the problem solver to first examine characteristics of the problem at hand and then capitalize on them in devising an algorithmic winning strategy. Such a problem-solving process yields not only the algorithmic solution but also its justification. The focus on problem characteristics expresses the highest level (level 4) of abstraction in the ladder of **abstraction levels** during algorithm design [6]. In particular, this level is higher than the program level (level 2) of this ladder, which corresponds to the operational perspective that focuses on the actual algorithmic instructions.

The illustrated declarative perspective in the game solutions expresses suitable employment of the component of *control* in Schoenfeld's cognitive model of problem solving [2]. This component "directs and monitors" progress in the process and combines the invocations of relevant resources and heuristics as well as justifications. Invoked *resources* involve mathematical properties such as polygon characteristics, list locations, parity, modular arithmetic, and number characteristics. They also involve game features such as pairing, invariance, and pre-processing. Invoked *heuristics* involve problem decomposition, modification, simplification, and more. Suitable invocations and applications of these elements paved the way to elegant game solutions that were displayed here.

A primary additional component of the cognitive model is that of *beliefs*, including beliefs in the way to approach a problem and progress and evaluate the outcome. The main difference between more competent and less competent problem solvers stems from the demonstration of more proper and less proper control and beliefs [2]. Many problem solvers that we described followed an operational perspective that was insufficient for obtaining sound outcomes, in terms of suitable algorithmic solutions and rigorous justifications. The competent problem solvers sought sound underlying patterns prior to, or together with the operative outcomes.

The different practices also affected creative behaviors. Those who expressed divergent, flexible thinking while seeking patterns reached constructive ideas on which they capitalized, while those who were focused right away on the final algorithmic outcomes demonstrated limited points of view and fixation. One must develop **awareness** of the important role of the elements described and illustrated here. Such development may occur with realization of the differences between the suitable and less suitable, or unsuitable, routes for progress.

*Game Theory - From Idea to Practice*
