Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Newbie questionby AnomalousMonk (Archbishop) |
on Aug 23, 2022 at 17:07 UTC ( [id://11146330]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|