#Boxes of Balls Puzzle

1 messages · Page 1 of 1 (latest)

chrome cairn
#

Problem: There are n transparent boxes, each with some number of balls in them. Two players take turns, each choosing one box and taking at least one ball from that box. When a box is empty, it is discarded. The last player to clear all boxes wins. Determine if player one has a winning strategy given some list of positive integers. Don't assume player two will fall into a mistake move because he also wants to win - so he is just as smart as player one.

Cheers: DevHC

uncut axle
#

The instructions are somewhat unclear. Could you please provide more detailes and restructure your instructions? Specifically, who are the players, and how do they interact with the program? Can they see the number of balls? What constitutes a winning strategy and what is considered a mistake? Additionally, could you include an example of the input and output?

It seems that both player could simply enter the lowest possible option each time (1) number to win and it would be advantageous to the last person who draws.

#

If it comes from somewhere like codewar, leetcode, project euler, etc, you can attach the link to your instructions.

chrome cairn
#

Sure, in the program, you choose to be either Player One who plays first, or Player Two who plays second. The boxes are transparent and they can see the number of balls. The program will ask for an amount of boxes as input, then for each box it will ask for an amount of balls. After the inputs are entered the program will automatically find and execute the best move for each player.
Examples

How many boxes? 1
How many balls in box 0? 0
Do you want to play first? (Y/N) y
[0]
You lose
How many boxes? 1
How many balls in box 0? 1
Do you want to play first? (Y/N) y
[1]
You take 1 ball(s) from box 0
[0]
You win
How many boxes? 1
How many balls in box 0? 5
Do you want to play first? (Y/N) y
[5]
You take 5 ball(s) from box 0
[0]
You win
How many boxes? 2
How many balls in box 0? 1
How many balls in box 1? 1
Do you want to play first? (Y/N) y
[1, 1]
You take 1 ball(s) from box 0
[0, 1]
Rival takes 1 ball(s) from box 1
[0, 0]
You lose
How many boxes? 2
How many balls in box 0? 1
How many balls in box 1? 2
Do you want to play first? (Y/N) y
[1, 2]
You take 1 ball(s) from box 1
[1, 1]
Rival takes 1 ball(s) from box 0
[0, 1]
You take 1 ball(s) from box 1
[0, 0]
You win
How many boxes? 5
How many balls in box 0? 1
How many balls in box 1? 2
How many balls in box 2? 3
How many balls in box 3? 4
How many balls in box 4? 5
Do you want to play first? (Y/N) y
[1, 2, 3, 4, 5]
You take 1 ball(s) from box 0
[0, 2, 3, 4, 5]
Rival takes 3 ball(s) from box 3
[0, 2, 3, 1, 5]
You take 5 ball(s) from box 4
[0, 2, 3, 1, 0]
Rival takes 2 ball(s) from box 1
[0, 0, 3, 1, 0]
You take 2 ball(s) from box 2
[0, 0, 1, 1, 0]
Rival takes 1 ball(s) from box 2
[0, 0, 0, 1, 0]
You take 1 ball(s) from box 3
[0, 0, 0, 0, 0]
You win
chrome cairn
uncut axle