<?xml version="1.0" encoding="windows-1252"?>
<node id="173273" title="Vampire Numbers" created="2002-06-10 15:25:42" updated="2005-08-15 07:56:40">
<type id="1042">
CUFP</type>
<author id="118343">
YuckFoo</author>
<data>
<field name="doctext">
More recreational math here. Again I was reading some
book by [http://www.pickover.com/|Clifford Pickover],
and heard about Vampire Numbers. &lt;p&gt;

A Vampire Number is equal to a product of it's digits 
like 1435 = 41 * 35. I think the name comes from a 
reference to such a number in an Anne Rice novel. &lt;p&gt;

So I went hunting for more vamps. This program only
looks for products of two factors, it would be interesting
to look for products of more than two factors. &lt;p&gt;

Algorithm is basically to generate a list of orderings
of the digits (1234, 1243, 1342, 1324, ...), not taking
the trouble to eliminate duplicates. &lt;p&gt;

Next each ordering is split at each digit and tested
(1*234, 12*34, 123*4). &lt;p&gt;

Of note is 153. In addition to being a [161681|Triangle Number]
(1+2+3+...+17), it is also a self-cube-referential number
(1**3 + 5**3 + 3**3), a sum of factorials (1! + 2! + 3! + 4! + 5!),
and a Vampire Number (3 * 51). &lt;p&gt;

VampFoo &lt;p&gt;

&lt;b&gt;Update:&lt;/b&gt; The book is 'The Loom of God'. A 40-digit V-num is
listed there: 98765432198765432198 * 98765432198830604534 =
9754610597415368368844499268390128385732, whew! &lt;p&gt;

&lt;readmore&gt;

&lt;code&gt;

#!/usr/bin/perl

   use strict;

   if (@ARGV &lt; 2) {
      print STDERR "\nUsage: $0 firstnumber lastnumber\n\n";
   }

   my ($beg, $end) = @ARGV;
   my ($test, $this, $that);

   for $test ($beg..$end) {
      ($this, $that) = factors($test);
      if ($this ne '') {
         print "$test = $this * $that\n";
      }
   }

#-----------------------------------------------------------
sub factors {

   my ($target) = @_;
   my ($order, $olist);
   my ($split, $slist);

   $olist = orderings($target);

   for $order (@{$olist}) {

      #print "$order\n";

      $slist = splittings($order);

      for $split (@{$slist}) {

         #print "$split-&gt;[0] $split-&gt;[1]\n";

         if ($split-&gt;[0] * $split-&gt;[1] == $target) {
            return ($split-&gt;[0], $split-&gt;[1]);
         }
      }
   }
}

#-----------------------------------------------------------
sub splittings {

   my ($num) = @_;
   my (@digits) = split('', $num);
   my (@list, @useds);

   while (@digits &gt; 1) {
      push(@useds, shift(@digits));
      push (@list, [join('', @useds), join('', @digits)]);
   }

   return \@list;
}

#-----------------------------------------------------------
sub orderings {

   my ($num) = @_;
   my (@digits) = split('', $num);

   my (@list, $sublists, $sub, $this);

   if (@digits == 1) { return [$digits[0]]; }

   for (1..@digits) {

      $this = shift(@digits);
      $sublists = orderings(join('', @digits));

      for $sub (@{$sublists}) {
         push(@list, "$this$sub");
      }

      push(@digits, $this);
   }
   return \@list;
}

&lt;/code&gt;

</field>
</data>
</node>
