Please enter your email address or userHandle.
/* A C++ program to find Grundy Number for a game which is one-pile version of Nim. Game Description : The game starts with a pile of n stones, and the player to move may take any positive number of stones upto k only. The last player to move wins. */ #include<bits/stdc++.h> using namespace std; // A function to Compute Grundy Number of 'n' // Only this function varies according to the game int calculateGrundy (int n,int k) { if (n == 0) return (0); if (n == 1) return (1); if (n == 2) return (2); if (n == 3) return (3); else{ return (n%(k+1)); } } // Driver program to test above functions int main() { int n = 47; int k=3; // you can change the value of k accordingly as you are allowed to pick upto k stones printf ("%d", calculateGrundy (n,k)); return (0); }
https://ide.geeksforgeeks.org/0VR3eEXGzf
3