Applying dynamic programming to a simple two-person game of perfect information
Since you want to calculate $X(1), X(2), X(3)$,... and not just some $X(i)$, you can start from $X(1)$. Let's denote the case where there is a winning strategy for first player by $1$ and the other case by $0$.

Clearly, value of $X(i)$ for $i \in \{1,2,3,4,5\}$ is $1$. Let's store the values of $X(i)$ that we computed in an array. For $i&gt;5$, if at least one of the values of $X(i-2), X(i-3), X(i-5)$ is $0$, then the value of $X(i)$ will be $1$. If none of them is $0$, then the value of $X(i)$ will be $0$.