Skip to main content
3 of 10
added 1 character in body
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214

#Pyth, 71 bytes

x[.EmqQ*shdsed.cs.pM.cK`Q/lK2 2qsP{*MyPQQ&P_hyQP_Q<.&QhQP_QqQsm^sdlKK)1

Try it here! or Verify the test cases.

Alternative solution, 71 bytes:

x[.EmqQ*shdsed.cs.pM.cK`Q/lK2 2qsP{*MyPQQ&P_hyQP_Q&.AjQ2P_QqQsm^sdlKK)1

This returns -1 for False, 0 for Vampire, 1 for Perfect, 2 for Sophie Germain, 3 for Mersenne and 4 for Narcissistic. In case more are truthy, this picks the one with the lowest index. Unfortunately, this memory errors for the following test cases: 33550336, 16758243290880.


#Explanation

##Vampire (≈ 30 bytes)

.EmqQ*shdsed.c.nsM.cK`Q/lK2 2

                  .c `Q/lK2      Get all combinations of the input's digits of half its length.
                .pM              Get all possible permutations of each.
             .cs            2    Get all possible two-number combinations, flattened.
.EmqQ*shdsed                     Check if any has the product equal to the input.

##Perfect (10 bytes)

qsP{*MyPQQ

q        Q   Is equal to the input?
 s           The sum of:
   {*MyPQ    Its divisors,
  P          Popped (since we want the proper divisors).

##Sophie Germain (9 bytes)

&P_hyQP_Q

      P_Q    Is the input prime?
 P_hy        Is the input doubled + 1 prime?
&            Logical AND.

##Mersenne (9 bytes)

<.&QhQP_Q

<             Is smaller?
 .&             Logical AND between:
   Q              The input
    hQ             And the input + 1 
              than:
      P_Q       Is the input prime?

In the alternative approach, this part is changed to .AjQ2P_Q.

##Narcissistic (10 bytes)

qQsm^sdlKK

q            Is equal?
 Q             The Input
   m^sdlKK     Each of its digits raised to the power of the length
  s            Summed.
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214