Yay, tilly seems to have a correct (and prettier than mine) solution! I knew there was a way to make the basic algorithm neater. For those of you doing the pairs method, can you come up with a solution with a best score of 65 for the following 100 numbers?
16 16 9 5 12 14 18 10 12 20 20 10 10 20 11 18 5 7 19 11 2 6 15 5 20 5 +6 18 2 6 20 4 4 18 8 12 7 14 10 10 9 12 12 8 7 11 19 3 12 12 2 20 13 +18 15 12 2 8 3 19 20 20 1 15 14 19 17 13 9 15 20 13 5 3 19 2 8 14 15 +7 11 11 7 11 9 3 2 7 14 12 20 20 1 17 5 5 11 4 15 15
My order is:

shift 16, shift 16, shift 9, pop 15, pop 15, pop 4, shift 5, shift 12, pop 11, pop 5, shift 14, shift 18, shift 10, shift 12, shift 20, shift 20, shift 10, shift 10, shift 20, shift 11, shift 18, shift 5, shift 7, shift 19, shift 11, shift 2, pop 5, pop 17, pop 1, pop 20, pop 20, pop 12, pop 14, pop 7, pop 2, pop 3, pop 9, pop 11, pop 7, pop 11, pop 11, pop 7, pop 15, pop 14, pop 8, pop 2, pop 19, pop 3, shift 6, shift 15, shift 5, shift 20, shift 5, shift 6, shift 18, shift 2, shift 6, shift 20, shift 4, shift 4, shift 18, shift 8, shift 12, shift 7, shift 14, shift 10, shift 10, shift 9, shift 12, shift 12, shift 8, shift 7, shift 11, shift 19, shift 3, shift 12, shift 12, shift 2, shift 20, shift 13, shift 18, shift 15, shift 12, shift 2, shift 8, shift 3, shift 19, shift 20, shift 20, shift 1, shift 15, shift 14, shift 19, shift 17, shift 13, shift 9, shift 15, shift 20, shift 13, ? 5

tilly's order is:

pop 15, pop 15, shift 16, pop 4, shift 16, pop 11, shift 9, pop 5, shift 5, pop 5, pop 17, shift 12, pop 1, shift 14, shift 18, shift 10, shift 12, pop 20, pop 20, pop 12, pop 14, pop 7, pop 2, pop 3, pop 9, pop 11, pop 7, pop 11, pop 11, pop 7, pop 15, pop 14, pop 8, shift 20, pop 2, shift 20, pop 19, shift 10, pop 3, pop 5, pop 13, shift 10, pop 20, shift 20, pop 15, pop 9, pop 13, shift 11, shift 18, shift 5, shift 7, pop 17, pop 19, shift 19, shift 11, shift 2, shift 6, pop 14, pop 15, pop 1, pop 20, shift 15, shift 5, pop 20, shift 20, pop 19, shift 5, pop 3, pop 8, pop 2, pop 12, shift 6, shift 18, shift 2, shift 6, pop 15, shift 20, pop 18, shift 4, shift 4, shift 18, shift 8, shift 12, shift 7, pop 13, pop 20, pop 2, shift 14, shift 10, shift 10, shift 9, pop 12, pop 12, pop 3, pop 19, pop 11, pop 7, pop 8, pop 12, shift 12

I'm still trying to figure out why our solutions are different, while still arriving at the same solution.


In reply to Re: Puzzle: Given an array of integers, find the best sequence of pop / shift... by TedPride
in thread Puzzle: Given an array of integers, find the best sequence of pop / shift... by TedPride

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.