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
-
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.
|