Problem 44647. Win all the time!
This is a 2-players game. One of them is your algorithm. Your algorithm must win in all games.
In this game there are 3 rows and every row has some lines like this:
1) |||||||||| 2) |||||||| 3) |||||
You can choose a row and remove some lines from the row.
Rule 1: You should remove the lines only in one row.
Rule 2: In your turn, you should remove at least one line.
As input you have row info like this:
[4,5,6]
It means there are 4 lines in row1, 5 lines in row2 and 6 lines in row3.
You should return 2 numbers as output that one of them is row number and other is number of lines you want to remove from the row.
This function repeated to remove all the lines. If you remove the last line, you lose. So you should force your competitor to take the last line.
At the start it's your turn and input is [10,10,10].
Good luck!
Solution Stats
Problem Comments
-
2 Comments
Nice problem! Per Solution 1536525 I think you can safely increase the number of iterations in the Test Suite to 1000 or 2000. You could also add a second case, identical to the first except choosing L randomly. —DIV
Tip. This is called Game of Nim. https://en.wikipedia.org/wiki/Nim
Solution Comments
Show commentsProblem Recent Solvers15
Suggested Problems
-
5902 Solvers
-
234 Solvers
-
9734 Solvers
-
515 Solvers
-
55 Solvers
More from this Author18
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!