Totally useless but a little bit of fun with a silly mathematical property:

#!/usr/bin/env perl + + use strict; + use warnings; + use List::Util qw(sum); + + # For each $n, convert $n to hex digits, add the digits together. If t +he # result has more than one hex digit, repeat this process adding the + # digits together. When there is only one hex digit remaining, if the + # digit is a '5', an 'a', or an 'f', the original number was divisible + # by 5. + + for my $n (1..100) { + my $h = sprintf '%x', $n; + while(length($h) > 1) { + $h = sprintf '%x', sum(map {hex $_} split //, $h); } + print "$n is a multiple of 5\n" if $h =~ m/^[5af]$/; + }

Output:

5 is a multiple of 5 10 is a multiple of 5 15 is a multiple of 5 20 is a multiple of 5 25 is a multiple of 5 30 is a multiple of 5 35 is a multiple of 5 40 is a multiple of 5 45 is a multiple of 5 50 is a multiple of 5 55 is a multiple of 5 60 is a multiple of 5 65 is a multiple of 5 70 is a multiple of 5 75 is a multiple of 5 80 is a multiple of 5 85 is a multiple of 5 90 is a multiple of 5 95 is a multiple of 5 100 is a multiple of 5

Dave


In reply to Re: Match multiple number by davido
in thread Match multiple number by IB2017

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.