Six is a number perfect in itself, and not because God created all things in six days; rather, the converse is true. God created all things in six days because the number six is perfect.
I am fascinated by numbers. As were Sophie Germain and Marin Mersenne. To be more specific, these two were fascinated by primes: a number with only two integer divisors: itself and 1
. In fact, they were so fascinated by primes that classes of primes were named after them:
A Mersenne prime is a prime number which can be generated by the formula 2p - 1 where p
is a prime. For example, 7 = 2^3 - 1
therefore 7
is a Mersenne prime.
A Germain prime is similar. It is a prime number that when plugged into the formula 2p + 1
it also produces a prime. E.g. 11 is Germain as 2*11 + 1 = 23
which is prime.
But now let's move on to the next three numbers: perfect, vampire and narcissistic numbers.
A perfect number is very easy to understand. It can be easily defined as
A number where all its divisors except itself sum to itself. For example, 6 is a perfect number as the divisors of 6 (not including 6) are 1,2,3 which sum to make 6.
A vampire number may be the most difficult to code. A vampire number is a number whose digits can be split into two numbers, of equal length, made from all those digits, that when multiplied, produce the original number. Leading 0s aren't allowed in either of the numbers E.g. 136,948 = 146 x 938
Finally a narcissistic number, probably the hardest to understand. A narcissistic number is a number in which the individual digits, raised to the power of the total number of digits sum to make the original number. A single digit number has to be narcissistic.
For example, 8,208 is narcissistic:
84 + 24 + 04 + 84 = 4,096 + 16 + 0 + 4,096 = 8,208
Your task is to create a program that will take an integer and return what category it fits into. The categories are Mersenne
, Germain
, Perfect
, Vampire
, Narcissistic
and False
. Every number that doesn't fit into the first five categories is False
. False
doesn't have to necessarily be a falsy value.
If a value fits in more than one category, e.g. 3
, you may output any correct result.
Output can be in any form, for example, 6 different numbers, as long as you say what it is in your answer.
Even if it is shorter, you aren't allowed to hard code each number as that ruins maths.
This is a code-golf so shortest code wins!
Examples
Input -> Output
10 -> False
7 -> Mersenne
8208 -> Narcissistic
28 -> Perfect
153 -> Narcissistic
2 -> Germain
17 -> False
16,758,243,290,880 -> Vampire
31 -> Mersenne
33,550,336 -> Perfect
173 -> Germain
136,948 -> Vampire