Oh. Yes, I deliberately avoided suggesting a different data format since original poster inquired about how to simplify his code. You are right that the data format complicates matters needlessly - in fact, it is very poorly chosen since the total grows without bounds, so you cannot easily encode streams of arbitrary length using this format, whereas by simply passing along the first value of the stream before storing deltas, the first element of the encoded stream has a constant size regardless of the stream's length.

I wasn't actually golfing per se though. :-) I actually consider the code production quality. The only opaque location in my code, IMHO, is the $_[0] = -$_[0] bit, in which as I noted the opacity is a matter of math rather than Perl, and because I saw it is unclear and was intending this to be production quality code, I added a comment so the next person to read it would know the intent without having to re-deduce the algorithm from the code to understand what's going on. Personally, I prefer a slightly opaque and efficient solution clarified by a comment over a swathe of statements that do the same thing "simplemindedly". Self-documenting does not equal easily maintainable, IMHO. That's what God gave us comments for. :-) Anyway, I think I went off on a bit of a tangent here.. </soapbox>

Makeshifts last the longest.


In reply to Re^5: Perl Drag Racing - sum/delta list by Aristotle
in thread Perl Drag Racing - sum/delta list by John M. Dlugosz

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.