# Test if a given number is a Vampire Number [duplicate]

EDIT: In the interest of increasing the complexity, i've added more to the challenge.

In mathematics, a vampire number (or true vampire number) is a composite natural number v, with an even number of digits n, that can be factored into two integers x and y each with n/2 digits and not both with trailing zeroes, where v contains precisely all the digits from x and from y, in any order, counting multiplicity. x and y are called the fangs.

Pseudovampire numbers

Pseudovampire numbers are similar to vampire numbers, except that the fangs of an n-digit pseudovampire number need not be of length n/2 digits. Pseudovampire numbers can have an odd number of digits, for example 126 = 6×21.

### Input

Accept Numbers from command line or stdin

### Output

• "1260 = 21 * 60" (smaller fang first if the number is a Vampire.)
• "1261 is not a Vampire Number." (if the number is not a Vampire number)
• "126 = 6 * 21". (if the number is a Pseudovampire number)

EDIT: If the number has multiple fangs, display it so.

x = fang1a * fang1b = fang2a * fang2b

• I've decided not to include Prime vampire's, i won't go overboard with it. Jan 28, 2011 at 11:05
• Maybe i should add Printing if its a Vampire or a PseudoVampire, what do you guys say? Jan 28, 2011 at 11:07
• What about multiple pairs of fangs? Jan 28, 2011 at 11:42
• @gnibbler, i'll ammend it. Jan 28, 2011 at 13:28
• @Nakilon, print them in the increasing order. fang1a appears before fang2a when fang1a < fang2a Jan 29, 2011 at 5:58

# Python - 188 chars

Doesn't do Pseudovampire numbers

from itertools import*
n=input()
a=[]
for i in map("".join,permutations(n)):x,y=int(i[::2]),int(i[::-2]);a+=[(x,y)]*(x*y==n)
print n,a and"=%s*%s"%min(a)or"is not a Vampire Number"

• Also doesn't handle multiple pairs (for 125460) and space missed after =. Jan 28, 2011 at 20:12
• (checked here) Jan 28, 2011 at 20:22
• @Nakilon, this answer predates the amendment for multiple pairs Jan 29, 2011 at 0:02

# Ruby, 190 chars

o=[]
[*x.chars].permutation{|r|a=r.pop(x.size/2).join.to_i
r=r.join.to_i
o|=[[a,r]]if a<=r&&a*r==x.to_i}
puts x+(o.any? ? o.map{|i|" = "+i*" * "}*"":" is not a Vampire Number.")