in reply to Re^2: Puzzle: Given an array of integers, find the best sequence of pop / shift...
in thread Puzzle: Given an array of integers, find the best sequence of pop / shift...
imagine a 6 element list...
The beginning, bottom row is the number, top row is odds/evens flag. 1 0 1 0 1 0 5 1 3 4 5 3 player 1 totals the odds and the evens, decides to go for odds, and takes from the left 1 0 1 0 1 0 1 3 4 5 3 player 2 has to take an even element, lets say from the right 1 0 1 0 1 0 1 3 4 5 player 1 is after odds, so takes from the right 1 0 1 0 1 0 1 3 4 hmmm, player two is left with the evens again. 1 0 1 0 1 0 1 3 player 1 sticks with odds 1 0 1 0 1 0 1 player two takes the last even element, and loses
If you try this strategy on the example numbers the OP gave, you win by ten, which is as good as strategy in the OP's example code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Puzzle: Given an array of integers, find the best sequence of pop / shift...
by McDarren (Abbot) on Mar 20, 2006 at 12:22 UTC | |
by davidj (Priest) on Mar 20, 2006 at 12:36 UTC | |
by McDarren (Abbot) on Mar 20, 2006 at 12:53 UTC | |
by davidj (Priest) on Mar 20, 2006 at 14:01 UTC |