Re: Puzzle: Given an array of integers, find the best sequence of pop / shift...by McDarren (Abbot)
|on Mar 20, 2006 at 03:20 UTC||Need Help??|
Unless I'm missing something, I reckon your solution is a lot more complex than it needs to be.
Given that "the other player also picks his best move", then all you need to do is determine which produces the higher score - a pop-first, or a shift-first.
This is my go at it:
Update: To test how long it takes with 1000 numbers I added the following lines:.
And I get something like this:
PS: Like the OP, I'm not 100% sure that I'm getting correct results - and I'm not sure how to verify it for very large ranges, I guess I'll just wait for some more responses :)
Update 2: - as tilly has pointed out, my solution is wrong. I kindof suspected that it would be - because it seemed too simple. And although I acknowledged further down in the thread that it was wrong, I forgot to add an update here.