One path to learning is to take a problem one step further (and then repeat, etc.).

In your OPed code and (I think) in all the replies, the sign of the number being tested is ignored through the use of abs.

What happens if you do not ignore the sign of the number, so that, e.g., -321 becomes the list (-3, 2, 1) with the sign applying to only the first digit? Is any interesting property of the problem or of numbers in general revealed?

Remember that Perl will seamlessly convert numbers back and forth between numeric and string representations. If -321 is represented as '-321', might regular expressions be used to extract substrings that might then be treated as numbers? (Please see perlre, perlretut, and perlreref/perlrequick.)


Give a man a fish:  <%-{-{-{-<


In reply to Re: Newbie question by AnomalousMonk
in thread Newbie question by oldB51

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.