in reply to Puzzle: Given an array of integers, find the best sequence of pop / shift...

Notice that if the first person takes a number which is at an odd index, the first person can only choose an even index number and vice versa. This strategy can be maintained through out the game by the first person so by summing the odd and even numbers and picking accordingly the first person can garantue a tie, but most likely win.
  • Comment on Re: Puzzle: Given an array of integers, find the best sequence of pop / shift...

Replies are listed 'Best First'.
Re^2: Puzzle: Given an array of integers, find the best sequence of pop / shift...
by tilly (Archbishop) on Mar 20, 2006 at 17:26 UTC
    You can tie or win with this strategy, but you don't get the best possible score. So it doesn't solve the puzzle.
Re^2: Puzzle: Given an array of integers, find the best sequence of pop / shift...
by jdporter (Paladin) on Mar 20, 2006 at 11:23 UTC

    What the 4377 are you talking about? They have no choice about indexes. They can only take from one end of the list or the other. Theoretically, both players can choose to always shift, which means they're both doing even indexes all the time. But that means nothing.

    Anyway, your "strategy" is too simple to work, because any successful strategy doesn't ignore the actual values of the numbers in the list. :-)

    But maybe you have some other meaning for the word "index" in mind.

    We're building the house of the future together.
      Nope, he's spot on. The decision player one gets to make is at the beginning.

      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.

      ---
      my name's not Keith, and I'm not reasonable.
        Hang about.....

        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 ;)