This is just for my or for future readers' reference... Please correct me if there's anything wrong or not explained properly. One reason I type this out is because I see code examples that use voodoo I'm not yet accustomed to. So maybe I can help someone else that reads this in the future. =)

The expression $_ & 1 will evaluate to zero (false) for any even number $_. This uses the bitwise operator &...

Translate both numbers ($_ and 1) to their binary formats and fill the lesser number with leading zeros (13 => 1101, 1 => 0001)... Perform the AND comparison between the numbers vertically and return that result. Since 1 is a number with many leading zeros, it cancels/falses out all higher order bits greater than 1 for the first number. The only way to make this expression true is to compare the two first bits as 1 AND 1. 1 is an active bit in binary when the first number is odd.


In reply to Re^2: Terse Code for Odd Numbers by deep submerge
in thread Terse Code for Odd Numbers by deep submerge

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.