login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A161531 The number of reachable states in a simple two-player counting game, in which each player starts with the pair (1,1) and one move is to add one of the opponent's numbers to one of your own numbers, but no number can grow above a pre-defined maximum n. The game continues until one of the players has no legal moves left. The winner is the one having the higher sum of his numbers. 1

%I #11 Jan 31 2023 08:13:24

%S 1,4,13,34,75,152,301,482,794,1197,1842,2522,3582,4772,6408,8229,

%T 10728,13285,16851,20569,25361,30380,36927,43251,51692,60199,70668,

%U 81452,95083,107664,124360,140539,160222,179821,204026,226607,255551,283320,316071,348155

%N The number of reachable states in a simple two-player counting game, in which each player starts with the pair (1,1) and one move is to add one of the opponent's numbers to one of your own numbers, but no number can grow above a pre-defined maximum n. The game continues until one of the players has no legal moves left. The winner is the one having the higher sum of his numbers.

%C For many n (1 <= n <= 100), optimal play leads to a draw.

%H Michael S. Branicky, <a href="/A161531/b161531.txt">Table of n, a(n) for n = 1..200</a>

%H Michael S. Branicky, <a href="/A161531/a161531.py.txt">Python program for generating b-file</a>

%e For n = 2 there are 4 valid states of the game: (A=1,1 B=1,1) starts the game. There is only one valid move, leading to (A=1,1 B=1,2). Now A also has only one choice (A=1,2 B=1,2), and B ends the game in the state (A=1,2 B=2,2) and wins. A has no valid move, since then one of his numbers would be larger than 2.

%o (Other) #include <climits> #include <iostream> #include <map> class State; typedef unsigned char byte; typedef std::map<State, int> ScoreMap; static inline int min(int a, int b) { return a < b ? a : b; } static inline int max(int a, int b) { return a > b ? a : b; } static inline int compare(int a, int b) { return a - b; }

%o static int MAX = 0; static ScoreMap score; struct State { byte a, b, c, d; State() : a(0), b(0), c(0), d(0) {} State(byte a, byte b, byte c, byte d) : a(min(a,b)), b(max(a,b)), c(min(c,d)), d(max(c,d)) {} int getChildren(State *children) { int n = 0; if (a + c <= MAX) children[n++ ] = State(c, d, a + c, b); if (a + d <= MAX && c != d) children[n++ ] = State(c, d, a + d, b);

%o if (a != b && b + c <= MAX) children[n++ ] = State(c, d, a, b + c); if (a != b && c != d && b + d <= MAX) children[n++ ] = State(c, d, a, b + d); return n; }; int getScore() { ScoreMap::iterator it = score.find(*this); if (it != score.end()) return it->second; State children[4]; int nchildren = getChildren(&children[0]); int iscore; if (nchildren == 0) { iscore = compare(a + b, c + d); } else { iscore = INT_MIN; for (int i = 0; i < nchildren; i++) iscore = max(iscore, -children[i].getScore()); } score.insert(ScoreMap::value_type(*this, iscore)); return iscore; }; };

%o static bool operator< (State a, State b) { if (a.a < b.a) return true; if (a.a > b.a) return false; if (a.b < b.b) return true; if (a.b > b.b) return false; if (a.c < b.c) return true; if (a.c > b.c) return false; if (a.d < b.d) return true; if (a.d > b.d) return false; return false; } int main() { std::cout << "max\tscore\tnstates" << std::endl; for (int max = 0; max < 1024; max++) { MAX = max; score.clear(); int iscore = State(1,1,1,1).getScore(); std::cout << max << "\t" << iscore << "\t" << score.size() << std::endl; } return 0; }

%o (Python)

%o from collections import deque

%o def a(n):

%o reach, pq = {((1, 1), (1, 1))}, deque([((1, 1), (1, 1))])

%o while len(pq) > 0:

%o qa, qb = pq.pop() # first tuple, qa, is player-to-move

%o for i, j in [(0, 0), (0, 1), (1, 0), (1, 1)]:

%o if qa[i] + qb[j] <= n:

%o qn = (qb, tuple(sorted((qa[i] + qb[j], qa[1-i]))))

%o if qn not in reach:

%o pq.append(qn)

%o reach.add(qn)

%o return len(reach)

%o print([a(n) for n in range(1, 41)]) # _Michael S. Branicky_, Jan 30 2023

%o (Python) # see link for faster generation of initial segment of sequence

%K nonn

%O 1,2

%A Roland Illig (roland.illig(AT)gmx.de), Jun 12 2009

%E a(39) and beyond from _Michael S. Branicky_, Jan 30 2023

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 11:39 EDT 2024. Contains 371969 sequences. (Running on oeis4.)