Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-18 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found