What is the maximum that Player 1 can win?How can I optimize this code that finds the GCD?What is the 10001st prime number?Playing “craps” for the winWhat does the Bob say?Find the number of possible infinite cycles that Bessie the Cow can get stuck inFinding the maximum GCD of all pairsCompute the number of ways a given amount (cents) can be changedGiven a binary tree, find the maximum path sumFind the maximum possible summation of differences of consecutive elements“What is the fastest solution for finding the maximum sum of a subarray?”
How do you transpose samples in cents?
Justifying Affordable Bespoke Spaceships
What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?
How do I find which software is doing an SSH connection?
Freewill and rewarding dogs
Make symbols atomic, without losing their type
How to make all magic-casting innate, but still rare?
How to write a nice frame challenge?
Boundaries and Buddhism
Umlaut character order when sorting
How can I improve my violin intonation for enharmonic notes?
Definition of 'vrit'
In Street Fighter, what does the M stand for in M Bison?
60's (or earlier) sci-fi short story about two spacecrafts exchanging plants for gold and thinking they got the better of the exchange
Can the pre-order traversal of two different trees be the same even though they are different?
Why does a Force divides equally on a Multiple Support/Legs?
sudo passwd username keeps asking for the current password
Predict the product from the reaction
Kelvin type connection
How did Frodo know where the Bree village was?
Why was New Asgard established at this place?
How "fast" do astronomical events occur?
Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?
Large-n limit of the distribution of the normalized sum of Cauchy random variables
What is the maximum that Player 1 can win?
How can I optimize this code that finds the GCD?What is the 10001st prime number?Playing “craps” for the winWhat does the Bob say?Find the number of possible infinite cycles that Bessie the Cow can get stuck inFinding the maximum GCD of all pairsCompute the number of ways a given amount (cents) can be changedGiven a binary tree, find the maximum path sumFind the maximum possible summation of differences of consecutive elements“What is the fastest solution for finding the maximum sum of a subarray?”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
This is a question that I encountered in one of the competitive coding tests. The question goes as follows:
A 2-player game is being played. There is a single pile of stones. Every stone has an amount (positive) written on top of it. At every turn, a player can take the top 1 or 2 or 3 stones and add to his kitty. Both players want to maximize their winnings. Assuming both players play the game optimally and Player 1 starts the game, what is the maximum amount that Player 1 can win?
I have devised the following recursive approach:
class Main
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
public static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
if (len-start <=3)
int val = 0;
for (int i=start; i<len; i++)
val += a[i];
return val;
int v1 = a[start] + (sum - currSum - a[start]) -
maxPlayer1(a, currSum + a[start], sum, start + 1, a.length);
int v2 = a[start] + a[start+1] + (sum - currSum - a[start] - a[start+1]) -
maxPlayer1(a, currSum + a[start] + a[start+1], sum, start + 2, a.length);
int v3 = a[start] + a[start+1] + a[start+2] + (sum - currSum - a[start] - a[start+1] - a[start+2]) -
maxPlayer1(a, currSum + a[start] + a[start+1] + a[start+2], sum, start + 3, a.length);
return Math.max(v1, Math.max(v2, v3));
I have checked my solution on a few inputs. Is my algorithm correct?
java algorithm programming-challenge recursion
$endgroup$
add a comment |
$begingroup$
This is a question that I encountered in one of the competitive coding tests. The question goes as follows:
A 2-player game is being played. There is a single pile of stones. Every stone has an amount (positive) written on top of it. At every turn, a player can take the top 1 or 2 or 3 stones and add to his kitty. Both players want to maximize their winnings. Assuming both players play the game optimally and Player 1 starts the game, what is the maximum amount that Player 1 can win?
I have devised the following recursive approach:
class Main
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
public static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
if (len-start <=3)
int val = 0;
for (int i=start; i<len; i++)
val += a[i];
return val;
int v1 = a[start] + (sum - currSum - a[start]) -
maxPlayer1(a, currSum + a[start], sum, start + 1, a.length);
int v2 = a[start] + a[start+1] + (sum - currSum - a[start] - a[start+1]) -
maxPlayer1(a, currSum + a[start] + a[start+1], sum, start + 2, a.length);
int v3 = a[start] + a[start+1] + a[start+2] + (sum - currSum - a[start] - a[start+1] - a[start+2]) -
maxPlayer1(a, currSum + a[start] + a[start+1] + a[start+2], sum, start + 3, a.length);
return Math.max(v1, Math.max(v2, v3));
I have checked my solution on a few inputs. Is my algorithm correct?
java algorithm programming-challenge recursion
$endgroup$
3
$begingroup$
A few inputs? Nope. You need a lot of inputs. One thing to do is to test your solution against more inputs. This way, you won't need to ask whether your algorithm is correct or not; you know your algorithm is right. Therefore, test some more inputs, so that you know your algorithm works correctly.
$endgroup$
– Justin
8 hours ago
4
$begingroup$
There is nothing wrong with posting the unit tests you already implemented as an appendix in your question. This makes our task helping you easier. When asking whether your algorithm is correct, this rings bells here. I suggest to read the policy: codereview.stackexchange.com/help/on-topic
$endgroup$
– dfhwze
8 hours ago
$begingroup$
A "pile of stones" together with "written on top" sounds a lot like the players would only be able to look at the top stone, with the scores of all other stones being a secret until the top stone is removed. This should be clarified before the algorithm can be analyzed.
$endgroup$
– Roland Illig
2 hours ago
add a comment |
$begingroup$
This is a question that I encountered in one of the competitive coding tests. The question goes as follows:
A 2-player game is being played. There is a single pile of stones. Every stone has an amount (positive) written on top of it. At every turn, a player can take the top 1 or 2 or 3 stones and add to his kitty. Both players want to maximize their winnings. Assuming both players play the game optimally and Player 1 starts the game, what is the maximum amount that Player 1 can win?
I have devised the following recursive approach:
class Main
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
public static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
if (len-start <=3)
int val = 0;
for (int i=start; i<len; i++)
val += a[i];
return val;
int v1 = a[start] + (sum - currSum - a[start]) -
maxPlayer1(a, currSum + a[start], sum, start + 1, a.length);
int v2 = a[start] + a[start+1] + (sum - currSum - a[start] - a[start+1]) -
maxPlayer1(a, currSum + a[start] + a[start+1], sum, start + 2, a.length);
int v3 = a[start] + a[start+1] + a[start+2] + (sum - currSum - a[start] - a[start+1] - a[start+2]) -
maxPlayer1(a, currSum + a[start] + a[start+1] + a[start+2], sum, start + 3, a.length);
return Math.max(v1, Math.max(v2, v3));
I have checked my solution on a few inputs. Is my algorithm correct?
java algorithm programming-challenge recursion
$endgroup$
This is a question that I encountered in one of the competitive coding tests. The question goes as follows:
A 2-player game is being played. There is a single pile of stones. Every stone has an amount (positive) written on top of it. At every turn, a player can take the top 1 or 2 or 3 stones and add to his kitty. Both players want to maximize their winnings. Assuming both players play the game optimally and Player 1 starts the game, what is the maximum amount that Player 1 can win?
I have devised the following recursive approach:
class Main
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
public static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
if (len-start <=3)
int val = 0;
for (int i=start; i<len; i++)
val += a[i];
return val;
int v1 = a[start] + (sum - currSum - a[start]) -
maxPlayer1(a, currSum + a[start], sum, start + 1, a.length);
int v2 = a[start] + a[start+1] + (sum - currSum - a[start] - a[start+1]) -
maxPlayer1(a, currSum + a[start] + a[start+1], sum, start + 2, a.length);
int v3 = a[start] + a[start+1] + a[start+2] + (sum - currSum - a[start] - a[start+1] - a[start+2]) -
maxPlayer1(a, currSum + a[start] + a[start+1] + a[start+2], sum, start + 3, a.length);
return Math.max(v1, Math.max(v2, v3));
I have checked my solution on a few inputs. Is my algorithm correct?
java algorithm programming-challenge recursion
java algorithm programming-challenge recursion
edited 9 hours ago
dfhwze
2,815525
2,815525
asked 9 hours ago
User_TargaryenUser_Targaryen
1534
1534
3
$begingroup$
A few inputs? Nope. You need a lot of inputs. One thing to do is to test your solution against more inputs. This way, you won't need to ask whether your algorithm is correct or not; you know your algorithm is right. Therefore, test some more inputs, so that you know your algorithm works correctly.
$endgroup$
– Justin
8 hours ago
4
$begingroup$
There is nothing wrong with posting the unit tests you already implemented as an appendix in your question. This makes our task helping you easier. When asking whether your algorithm is correct, this rings bells here. I suggest to read the policy: codereview.stackexchange.com/help/on-topic
$endgroup$
– dfhwze
8 hours ago
$begingroup$
A "pile of stones" together with "written on top" sounds a lot like the players would only be able to look at the top stone, with the scores of all other stones being a secret until the top stone is removed. This should be clarified before the algorithm can be analyzed.
$endgroup$
– Roland Illig
2 hours ago
add a comment |
3
$begingroup$
A few inputs? Nope. You need a lot of inputs. One thing to do is to test your solution against more inputs. This way, you won't need to ask whether your algorithm is correct or not; you know your algorithm is right. Therefore, test some more inputs, so that you know your algorithm works correctly.
$endgroup$
– Justin
8 hours ago
4
$begingroup$
There is nothing wrong with posting the unit tests you already implemented as an appendix in your question. This makes our task helping you easier. When asking whether your algorithm is correct, this rings bells here. I suggest to read the policy: codereview.stackexchange.com/help/on-topic
$endgroup$
– dfhwze
8 hours ago
$begingroup$
A "pile of stones" together with "written on top" sounds a lot like the players would only be able to look at the top stone, with the scores of all other stones being a secret until the top stone is removed. This should be clarified before the algorithm can be analyzed.
$endgroup$
– Roland Illig
2 hours ago
3
3
$begingroup$
A few inputs? Nope. You need a lot of inputs. One thing to do is to test your solution against more inputs. This way, you won't need to ask whether your algorithm is correct or not; you know your algorithm is right. Therefore, test some more inputs, so that you know your algorithm works correctly.
$endgroup$
– Justin
8 hours ago
$begingroup$
A few inputs? Nope. You need a lot of inputs. One thing to do is to test your solution against more inputs. This way, you won't need to ask whether your algorithm is correct or not; you know your algorithm is right. Therefore, test some more inputs, so that you know your algorithm works correctly.
$endgroup$
– Justin
8 hours ago
4
4
$begingroup$
There is nothing wrong with posting the unit tests you already implemented as an appendix in your question. This makes our task helping you easier. When asking whether your algorithm is correct, this rings bells here. I suggest to read the policy: codereview.stackexchange.com/help/on-topic
$endgroup$
– dfhwze
8 hours ago
$begingroup$
There is nothing wrong with posting the unit tests you already implemented as an appendix in your question. This makes our task helping you easier. When asking whether your algorithm is correct, this rings bells here. I suggest to read the policy: codereview.stackexchange.com/help/on-topic
$endgroup$
– dfhwze
8 hours ago
$begingroup$
A "pile of stones" together with "written on top" sounds a lot like the players would only be able to look at the top stone, with the scores of all other stones being a secret until the top stone is removed. This should be clarified before the algorithm can be analyzed.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A "pile of stones" together with "written on top" sounds a lot like the players would only be able to look at the top stone, with the scores of all other stones being a secret until the top stone is removed. This should be clarified before the algorithm can be analyzed.
$endgroup$
– Roland Illig
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Usability
I have a remark about defining recursive functions.
You don't want consumers of your API to think about the intermediate variables and their initial value. The consumer does not care you are using recursion internally.
Make your recursive function private
.
private static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
And create a public
API entrypoint.
public static int maxPlayer1(int[] a)
final int sum = IntStream.of(a).sum();
return maxPlayer1(a, 0, sum, 0, a.length);
The consumer can now call your API without getting a headache:
public static void main(String[] args)
final int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
System.out.println(maxPlayer1(a));
As compared to the original code the consumer had to write.
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
$endgroup$
add a comment |
$begingroup$
A note on efficiency. Currently the code exhibit an exponential time complexity. It can be reduced significantly.
Notice that the same position is inspected more than once. For example, the opening sequences 3, 1
, 2, 2
and 1, 3
all lead to the same position. Further down the game the situation aggravates.
Keep track of the positions already inspected, and before diving into the recursion check whether it is still unknown. Since the position is just an integer (an amount of stones remaining), the cost of tracking is $O(n)$ space.
Further improvement is of course alpha-beta pruning.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f222413%2fwhat-is-the-maximum-that-player-1-can-win%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Usability
I have a remark about defining recursive functions.
You don't want consumers of your API to think about the intermediate variables and their initial value. The consumer does not care you are using recursion internally.
Make your recursive function private
.
private static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
And create a public
API entrypoint.
public static int maxPlayer1(int[] a)
final int sum = IntStream.of(a).sum();
return maxPlayer1(a, 0, sum, 0, a.length);
The consumer can now call your API without getting a headache:
public static void main(String[] args)
final int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
System.out.println(maxPlayer1(a));
As compared to the original code the consumer had to write.
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
$endgroup$
add a comment |
$begingroup$
Usability
I have a remark about defining recursive functions.
You don't want consumers of your API to think about the intermediate variables and their initial value. The consumer does not care you are using recursion internally.
Make your recursive function private
.
private static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
And create a public
API entrypoint.
public static int maxPlayer1(int[] a)
final int sum = IntStream.of(a).sum();
return maxPlayer1(a, 0, sum, 0, a.length);
The consumer can now call your API without getting a headache:
public static void main(String[] args)
final int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
System.out.println(maxPlayer1(a));
As compared to the original code the consumer had to write.
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
$endgroup$
add a comment |
$begingroup$
Usability
I have a remark about defining recursive functions.
You don't want consumers of your API to think about the intermediate variables and their initial value. The consumer does not care you are using recursion internally.
Make your recursive function private
.
private static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
And create a public
API entrypoint.
public static int maxPlayer1(int[] a)
final int sum = IntStream.of(a).sum();
return maxPlayer1(a, 0, sum, 0, a.length);
The consumer can now call your API without getting a headache:
public static void main(String[] args)
final int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
System.out.println(maxPlayer1(a));
As compared to the original code the consumer had to write.
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
$endgroup$
Usability
I have a remark about defining recursive functions.
You don't want consumers of your API to think about the intermediate variables and their initial value. The consumer does not care you are using recursion internally.
Make your recursive function private
.
private static int maxPlayer1(int[] a, int currSum, int sum, int start, int len)
And create a public
API entrypoint.
public static int maxPlayer1(int[] a)
final int sum = IntStream.of(a).sum();
return maxPlayer1(a, 0, sum, 0, a.length);
The consumer can now call your API without getting a headache:
public static void main(String[] args)
final int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
System.out.println(maxPlayer1(a));
As compared to the original code the consumer had to write.
public static void main(String[] args)
int a[] = 1,2,3,7,4,8,1,8,1,9,10,2,5,2,3;
int sum = 0;
for (int i=0;i<a.length; i++)
sum += a[i];
System.out.println(maxPlayer1(a, 0, sum, 0, a.length));
edited 7 hours ago
answered 7 hours ago
dfhwzedfhwze
2,815525
2,815525
add a comment |
add a comment |
$begingroup$
A note on efficiency. Currently the code exhibit an exponential time complexity. It can be reduced significantly.
Notice that the same position is inspected more than once. For example, the opening sequences 3, 1
, 2, 2
and 1, 3
all lead to the same position. Further down the game the situation aggravates.
Keep track of the positions already inspected, and before diving into the recursion check whether it is still unknown. Since the position is just an integer (an amount of stones remaining), the cost of tracking is $O(n)$ space.
Further improvement is of course alpha-beta pruning.
$endgroup$
add a comment |
$begingroup$
A note on efficiency. Currently the code exhibit an exponential time complexity. It can be reduced significantly.
Notice that the same position is inspected more than once. For example, the opening sequences 3, 1
, 2, 2
and 1, 3
all lead to the same position. Further down the game the situation aggravates.
Keep track of the positions already inspected, and before diving into the recursion check whether it is still unknown. Since the position is just an integer (an amount of stones remaining), the cost of tracking is $O(n)$ space.
Further improvement is of course alpha-beta pruning.
$endgroup$
add a comment |
$begingroup$
A note on efficiency. Currently the code exhibit an exponential time complexity. It can be reduced significantly.
Notice that the same position is inspected more than once. For example, the opening sequences 3, 1
, 2, 2
and 1, 3
all lead to the same position. Further down the game the situation aggravates.
Keep track of the positions already inspected, and before diving into the recursion check whether it is still unknown. Since the position is just an integer (an amount of stones remaining), the cost of tracking is $O(n)$ space.
Further improvement is of course alpha-beta pruning.
$endgroup$
A note on efficiency. Currently the code exhibit an exponential time complexity. It can be reduced significantly.
Notice that the same position is inspected more than once. For example, the opening sequences 3, 1
, 2, 2
and 1, 3
all lead to the same position. Further down the game the situation aggravates.
Keep track of the positions already inspected, and before diving into the recursion check whether it is still unknown. Since the position is just an integer (an amount of stones remaining), the cost of tracking is $O(n)$ space.
Further improvement is of course alpha-beta pruning.
answered 4 hours ago
vnpvnp
41.7k234106
41.7k234106
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f222413%2fwhat-is-the-maximum-that-player-1-can-win%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
$begingroup$
A few inputs? Nope. You need a lot of inputs. One thing to do is to test your solution against more inputs. This way, you won't need to ask whether your algorithm is correct or not; you know your algorithm is right. Therefore, test some more inputs, so that you know your algorithm works correctly.
$endgroup$
– Justin
8 hours ago
4
$begingroup$
There is nothing wrong with posting the unit tests you already implemented as an appendix in your question. This makes our task helping you easier. When asking whether your algorithm is correct, this rings bells here. I suggest to read the policy: codereview.stackexchange.com/help/on-topic
$endgroup$
– dfhwze
8 hours ago
$begingroup$
A "pile of stones" together with "written on top" sounds a lot like the players would only be able to look at the top stone, with the scores of all other stones being a secret until the top stone is removed. This should be clarified before the algorithm can be analyzed.
$endgroup$
– Roland Illig
2 hours ago