BrowserUk,
Update: I started this node indicating that I believed that I had proven that running it both ways was not guaranteed to produce an optimal solution. Then I updated it saying I had made a mistake. Now I am updating it again, quite confident that I have indeed proven that just running it both ways is not guaranteed to provide an optimum solution.
Consider the input:
7 6 7 0 0 0 7 0 6 0 1 -42 6
__DATA__
56 : [7 6 7 0 0 0 7] [0 6 0 1 -42 6]
42 : [0 6 7 0 0 0 7] [7 6 0 1 -42 6]
30 : [0 0 7 0 0 0 7] [7 6 6 1 -42 6]
28 : [0 0 6 0 0 0 7] [7 7 6 1 -42 6]
18 : [0 0 1 0 0 0 7] [7 7 6 6 -42 6]
16 : [0 0 1 0 0 0 6] [7 7 7 6 -42 6]
I believe that to "run it both ways", I simply need to swap the assignments of @a and @b. If that's the case, then you can see that this too produces the same incorrect result:
56 : [0 6 0 1 -42 6] [7 6 7 0 0 0 7]
42 : [7 6 0 1 -42 6] [0 6 7 0 0 0 7]
40 : [7 7 0 1 -42 6] [0 6 6 0 0 0 7]
28 : [7 7 6 1 -42 6] [0 0 6 0 0 0 7]
26 : [7 7 7 1 -42 6] [0 0 6 0 0 0 6]
16 : [7 7 7 6 -42 6] [0 0 1 0 0 0 6]
I haven't found an input that breaks if you sort the list and run it both ways but I am not inclined to think that makes a difference.
|