Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
More recreational math here. Again I was reading some book by Clifford Pickover, and heard about Vampire Numbers.

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.

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.

Algorithm is basically to generate a list of orderings of the digits (1234, 1243, 1342, 1324, ...), not taking the trouble to eliminate duplicates.

Next each ordering is split at each digit and tested (1*234, 12*34, 123*4).

Of note is 153. In addition to being a 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).


Update: The book is 'The Loom of God'. A 40-digit V-num is listed there: 98765432198765432198 * 98765432198830604534 = 9754610597415368368844499268390128385732, whew!

#!/usr/bin/perl use strict; if (@ARGV < 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->[0] $split->[1]\n"; if ($split->[0] * $split->[1] == $target) { return ($split->[0], $split->[1]); } } } } #----------------------------------------------------------- sub splittings { my ($num) = @_; my (@digits) = split('', $num); my (@list, @useds); while (@digits > 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; }

In reply to Vampire Numbers by YuckFoo

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, 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?

    What's my password?
    Create A New User
    NodeReaper takes a ball from the brass monkey

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2017-08-17 15:03 GMT
    Find Nodes?
      Voting Booth?
      Who is your favorite scientist and why?

      Results (288 votes). Check out past polls.