Vampire Number

Prize: 1st : Discord Nitro + Amnesia collection Steam key , 2nd : Discord Nitro Classic

Host: Brain Dead

Begins: Oct. 31, 2019
Ends: Nov. 30, 2019

Vampire Number

Other Event

Script for Vampire numbers


Create a script that will, based on input, return True if that input is a vampire number or False otherwise.

Quote (taken from Google, you can Google more for more info):

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

Condition for a number to be Vampire Number:

Has a pair number of digits. Lets call the number of digits : N

You can obtain the number by multiplying two integers, X and Y, each with N/2 digits. X and Y are called fangs.

The number can be made with all digits from X and Y, in any order and only using each digit once (see Examples 1250)

Both fangs cannot end simultaneously in 0.


1260 is a vampire number.

It's first fang is 60 and second fang is 21.

It's possible fangs are 12, 16, 10, 21, 26, 20, 61, 62, 60

It is a valid vampire number because 60 * 21 = 1260 and it breaks no conditions.

1250 is NOT a vampire number!

It's possible fangs are 12, 15, 10, 21, 25, 20, 51, 52, 50

You could get 1250 by multiplying it's two fangs 50 * 25 = 1250 BUT we can't write 1250 with numbers 0,2,5 (any order)

2500 is NOT a vampire number!

It's possible fangs are 25, 20, 20, 52, 50, 50

You could get 2500 by multiplying it's two fangs 50 * 50 = 2500 BUT ,aside from breaking the previous point, we're also also breaking condition where Both fangs cannot end simultaneously in 0.

First 25 vampire numbers are:

1260, 1395, 1435, 1530, 1827, 2187, 6880, 102510, 104260, 105210, 105264, 105750, 108135, 110758, 115672, 116725, 117067, 118440, 120600, 123354, 124483, 125248, 125433, 125460, 125500, ...


You are allowed to use only pure Python - no C!

You can use any standard library that you wish including non-standard libraries.

Code standards (PEP, organization, OOP etc) are NOT counted - only execution time is counted.

Your script HAS to have a function/method named is_vampire_number that takes one integer as a argument - this is for easier testing.
    Example for function:

def is_vampire_number(number: int) -> bool:
    # code
    # return True or False based on if number is a vampire number or not

    This function returns either True or False! No need to print anything! And no need to know/print fangs!

    If the number has multiple distinct sets of fangs the outcome is the same (True). For example 125460 has 2 possible sets of fangs (204, 615) and (246, 510) and will still return True.

Your is_vampire_number has to return the correct answer (True/False)
    It has to either throw ValueError or return False if invalid argument is passed to it.
    Valid argument is a natural number starting from 1 example 1,2,3....

You will be disqualified if you don't follow any of the above rules including:
    Your execution time takes more than 10s (see #Testing environment for specs)
    You hardcoded the answers - imagine your function as dumb, it doesn't know when will the first vampire number occur nor how many there are and which numbers are they. It ONLY knows the rules and algorithm on how to find one. So you CANNOT do this:

     def vampire_num(n):
       if n < 1260: return False
       ... # rest of code

    However, since your function knows the conditions from #Condition for a number to be Vampire Number you could do something similar - look at the first condition.
    You copy-pasted code from net that does the entire job for you - you can copy-paste code snippets, that's normal for a dev :) but you cannot copy-paste the entire solution that finds vampire numbers out of the box. What I mean by snippets is for example copy-pasting the source code for from itertools import permutations and editing it or finding a similar permutation algorithm with better performance for you needs and copy-pasting that.