Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Here's a piece of code that finds all Vampire numbers with factors smaller than the argument given:
#!/usr/bin/perl use strict; use warnings 'all'; my @vampire; foreach my $s (1 .. shift) { LOOP: foreach my $t (1 .. $s) { my $prod = $s * $t; my $cat = "$s$t"; foreach my $d (0 .. 9) { next LOOP unless eval "\$prod =~ y/$d/$d/ == \$cat =~ y/$d/$d/"; } push @vampire => [$prod, $s, $t]; } } @vampire = sort {$a -> [0] <=> $b -> [0]} @vampire; foreach my $vamp (@vampire) { printf "%4d * %4d = %8d\n" => @$vamp [1, 2, 0]; }

Note that if there is one vampire number (and there is), then we have an infinite number of vampire numbers. Proof: Suppose V = n * m is a vampire number. Then 10 * V = (10 * n) * m is a vampire number as well. qed.

Abigail

Here are the vampire numbers with factors smaller than 100:
  21 *    6 =      126
  51 *    3 =      153
  86 *    8 =      688
  60 *   21 =     1260
  93 *   15 =     1395
  41 *   35 =     1435
  51 *   30 =     1530
  87 *   21 =     1827
  81 *   27 =     2187
  86 *   80 =     6880

In reply to Re: Vampire Numbers by Abigail-II
in thread Vampire Numbers by YuckFoo

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2015-07-31 23:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (282 votes), past polls