Pathologically Eclectic Rubbish Lister PerlMonks

### 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 ( #537927=note: print w/replies, xml ) Need Help??

If you are shifting and popping, aren't the indices going to change as you go?

Well, actually - only as you shift. That is, each time you shift an element off the list, the index of each remaining element is reduced by one - no?

Therfore, this whole odds/evens thing won't work at all - or have I been smoking too much happy weed? ;)

(just kidding - I never touch the stuff ;)

• Comment on Re^4: Puzzle: Given an array of integers, find the best sequence of pop / shift...

Replies are listed 'Best First'.
Re^5: Puzzle: Given an array of integers, find the best sequence of pop / shift...
by davidj (Priest) on Mar 20, 2006 at 12:36 UTC
Yes, shifting and popping will change the index. However, the point the OP is trying to make is that the player who starts first can force the second player to take all evens or all odds from the original layout. With this ability, the first player can total the two possibilities and decide the outcome before the game even starts. Quite clever.

Dave
Okay, I understand what you are saying - but I'm still not sure if I buy it. Isn't this mistakenly assuming (like I did in my original reply) that each player (or at least player 2) will take the highest of the two available numbers at each turn?
Sure the 2nd player will take the higher of the two. But that is irrelevant, because that player can be forced to take all odd or all even. With that, the outcome is known in advance, and the first player will know which one (odd or even) to take for herself.

dave

Create A New User
Node Status?
node history
Node Type: note [id://537927]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-05-23 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (168 votes). Check out past polls.

Notices?