Doing this on my machine, the despicable snake language comes out ahead

Even a snake can do what other beasts can't. No need to worry. Perl doesn't have a stepping range operator, it doesn't even have a descending one. So the indices must be built every line through. OTOH, knowing that the input lines always contain 10 items, it is trivial to beat the snake:

qwurx [shmem] ~> time perl -lne 'BEGIN{$,=" "}print+(split)[9,7,5,3,1] +' in.txt >/dev/null real 0m1.589s user 0m1.588s sys 0m0.004s qwurx [shmem] ~> time python list.py in.txt >/dev/null real 0m2.204s user 0m2.188s sys 0m0.016s

And your snake code does - according to the spec Given a line of numbers from a file, print every 2nd number starting from the back - get it right only for an even number of integers:

qwurx [shmem] ~> python Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> line = "1 2 3 4" >>> line.split()[::-2] ['4', '2'] >>> line = "1 2 3 4 5" >>> line.split()[::-2] ['5', '3', '1'] >>> ^D

So, what does every 2nd number starting from the back mean? If we start from the back and take every 2nd, the output for the even example should be ['3','1'], and for the odd example ['4','2']. If we count every 2nd from the beginning, the output ought to be ['4','2'] for both cases.

Because you presented

Example:

1 22 3 -4 ==> -4 22

almost all code examples in this thread assumed that every 2nd meant counting from the beginning, but outputting in reverse order. Tell the snake to do that, and compare again.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re^3: printing every 2nd entry in a list backwards by shmem
in thread printing every 2nd entry in a list backwards by Anonymous Monk

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.