Vampire Numbers Program

  

For example, 1,435 is a vampire number as you can get 35 * 41 from it. I've managed to write a program to work out the vampire numbers for 4 digit numbers.

  1. Creepy Vampire Numbers
  2. List Of Vampire Numbers

Creepy Vampire Numbers

We have today a problem from recreational mathematics. A vampire number is a number v = x × y such that x and y are not both divisible by 10 and the digits of v consist of the digits of x and the digits of y. The number of digits n in the vampire number must be even, and the number of digits in each of the two fangs x and y must be half the number of digits in v.

List Of Vampire Numbers

A vampire number is. For instance 1260 = 21 × 60 and 1395 = 15 × 93 are both vampire numbers. Your task is to write a program that calculates the vampire numbers. A vampire number is a natural number with an even number of digits, that can be factored into two integers. These two factors are called the fangs, and must have the following properties: they each contain half the number of the digits of the original number.

York

Vampire Numbers Program

For instance 1260 = 21 × 60 and 1395 = 15 × 93 are both vampire numbers. Your task is to write a program that calculates the vampire numbers of n digits. When you are finished, you are welcome to or a suggested solution, or to post your own solution or discuss the exercise in the comments below. Skuba said Python brute force!

4 digits is quick, 6 takes around 4 minutes, too impatient for anything higher than that. #Vampire Numbers import math import time def main: #Variable Initialization numvampdigits = 0 numfangdigits = 0 fang1 = 0 fang2 = 0 evenvampcheck = 0 vampirenumber = 0 vampirestart = 0 vampireend = 0 fangstart = 0 fangend = 0 fangcheck = 0 contains = 0 count = 0 starttime = 0 #while loop necessary so if an even number is not entered then a new value can be prompted while evenvampcheck 0: #Get user input numvampdigits = vampinput #Check if entered number is even evenvampcheck = evenvamp(numvampdigits) starttime = time.time print('Calculating.' ) #Generate possible vampire numbers #define range using powers of ten vampirestart = 10.(numvampdigits - 1) vampireend = 10.(numvampdigits) - 1 vampirenumber = vampirestart numfangdigits = numvampdigits //2 fangstart = 10.(numfangdigits - 1) while vampirenumber.

   Coments are closed