Thread: Vampires

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    3

    Vampires

    http://www.madras.fife.sch.uk/maths/...s/fact020.html

    Hi, just thought I would share what I've been wanting to work on for several months, and just in the past couple of days finally decided to learn how to make.

    Vampire Number Finder/Hunter (name isn't important)

    There are other vampire numbers beside the multiplication type but for now I want to stick with just these to keep it simple.

    (## x ## x ##) Fangs: _ (min=2)
    (### x ###) Fang Digits: _ (min=2)

    I'll let this code snippet show you how far I've gotten:

    Code:
    #include <iostream>
    
    int main()
    {
        
        int digits;
        int t1 = 1;
        int t2 = 9;
        int i1;
        int i2;
        int i3;
        int i4;
        
        std::cout << "Fang Digits: ";
        std::cin >> digits;
        
        for (i1 = 1; i1 < digits; i1++)
        {
            t1 = t1 * 10;
        }
        
        for (i2 = 1; i2 < digits; i2++)
        {
            t2 = t2 * 10 + 9;
        }
        
        std::cout << t1 << " to " << t2 << std::endl;
        
        for (i3 = t1; i3 <= t2; i3++)
        {
            for (i4 = t1; i4 <= t2; i4++)
            {
                std::cout << i3 << " x " << i4 << " = " << i3 * i4 << std::endl;
            }
        }
        
        return 0;
    }
    I've been wracking my brain tying to figure out how to do different numbers of fangs without writing a bunch of different nested for loops...

    ps: I've been at this only 2 days. (can't get past pointers in most online tutorials)

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Could you explain exactly what you are trying to do?

    Find "vampire numbers" given say, the "fangs" are of n digits?

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    3
    hmm...

    well, the goal of the program is to run through all possabilities of the specified size of the multiplaction problem, during this process, and not shown in the program, each combination is "tested" to see if it is indeed a vampire number.

    I'll try and show what I mean...

    Fangs: 2
    Fang Digits: 2

    The above means that there is 1 multiplicand and 1 multiplier, and that both the multiplicand and multiplier are limited to 2 digit numbers. (10 to 99)

    my previous program showed the nested for loops creating all possibilities, within that loop (or hopefully something else i can come up with to make it more changeable) there would be maybe a simple test to see if the combined length of the digits of the multiplicand and multiplier would equal the digits within the answer. the next test might then use an array (just started to learn about them) to organize both sets of numbers (previously measured) and then subtract the 2. if 0 then true, and we have us a vampire number!

    10 x 10 = 100 *check - not same length
    10 x 11 = 110 *check - not same length
    ...
    15 x 93 = 1395 *check - same length; *check 1359 - 1359 = 0 - true;(organized by size in array if i can figure out how to seperate the digits)
    ...
    99 x 99 = 9801 *check - same length; *check 9999 - 0189 = 9810 - false;

    hope that answers your question...

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    What is the purpose of a vampire number?

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Originally posted by curlious
    What is the purpose of a vampire number?
    To eat lots and lots of CPU cycles.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    heh, apparently 1395 has 2 pairs of fangs as well, 15*93 and 31*45

    Here's my simple program to test with a given number:

    Code:
    #include <iostream>
    
    int main() {
    	int num = 1395; //number to test with
    	bool flag = false; //true if number is vampire
    	//loop through the possible factors
    	for (int i = 10; i < 100; i++) {
    		for (int j = i; j < 100; j++) {
    			if (i * j == num) {
    				std::cout<<i<<" and "<<j<<" are fangs of "<<num<<"\n";
    				flag = true;
    			}
    		}
    	}
    	if (!flag) {
    		std::cout<<num<<" is not a vampire number\n";
    	}
    	std::cin.get(); //wait for input in case not from command line
    	return 0;
    }
    Vampire numbers arent special at all, really.
    They just happen to have factors that, in decimal, have the same number of digits.

    Using this property, you pretty much can calculate all vampire numbers within a range, given enough time.
    My example doesnt do this well, since the loop should stop immediately when the first fangs are found.

    Once you know a vampire number, you can easily calculate all its fangs, given enough time.
    This is what my example does.

  7. #7
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    I wonder if these numbers follow any particular pattern...maybe after my exams are over I'll look into finding it. If indeed an inductive proof could be found then there should be an elegant recursive way to find the vampire numbers

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #8
    Registered User
    Join Date
    Dec 2003
    Posts
    3
    Good morning

    thanks for all the replys.
    I was wondering if you could help me out with something.

    Code:
        int fangs[n1];
        
        for (i2 = 0; i2 < n1; i2++)
        {
            fangs[i2] = t1;
        }
        
        for (i3 = n1 - 1; i3 >= 0; i3--)
        {
            for (i4 = t1; i4 <= t2; i4++)
            {
                fangs[i3] = i4;
                s1 = 1;
    
                for (i5 = 0; i5 < n1; i5++)
                {
                    s1 = s1 * fangs[i5];
                }
                std::cout << s1 << std::endl;
            }
        }
    the goal of my code here is to act like the previous nested for loops, but be changeable by how large the array is.

    It does work, kinda... it increments the last array to 99 and then continues on to the next, but doesn't quite act like the previous setup.

    So close... any ideas?

    Edit: http://hjem.get2net.dk/jka/math/vampires/
    This website has lots more information on vampire numbers, including some c source code someone made, (i'm not that good at reading code yet) and a possible pattern having to do with mod 9? I don't understand alot of whats there but maybe someone else will find it useful.
    Last edited by Amglco; 12-02-2003 at 03:54 PM.

  9. #9
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Originally posted by laserlight
    heh, apparently 1395 has 2 pairs of fangs as well, 15*93 and 31*45
    31 and 45 are not fangs of this vampire. There is no 4 in 1395.
    Originally posted by curlious
    What is the purpose of a vampire number?
    Apparently, prime vampire numbers (vampires with prime fangs) can be used to easily find large prime numbers.
    Last edited by pianorain; 12-03-2003 at 11:28 AM.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  10. #10
    Registered User
    Join Date
    Nov 2010
    Location
    Kolkata
    Posts
    1
    I don't think this page has a program to check whether an entered number is Vampire or not. I am providing a program to do so. It tells us whether it is Vampire or not, gives us all the possible fang pairs, and also gives you the number of fang-pairs available. Check it out...

    Code:
    Code:
    #include<stdio.h>
    #include<math.h>
    void sort(long int *z,long int i);
    void swap(long int *x,long int *y);
    main()
    {
    long int a,b,c,d,e,f,g=1,i=0,j,k,l,t=0,m,n;
    long int p[100],s[100];
    printf("Enter the darned number: ");
    scanf("%ld",&a);
    b=a;
    while (a>=1)
    {
    p[i]= (a%10);
    ++i;
    a/=10;
    }
    if ((i%2)!=0)
    printf("\n%ld has an odd (%ld) number of digits. It can't be a Vampire Number you dumbo!\n\n", b, i);
    else
    {
    sort(p,i);
    for (m=10;m<b;++m)
    {
    l=m;
    if ((b%l)==0)
    {
    n= (b/l);
    if ((((l%10)!=0) || ((n%10)!=0)) && ((l<(pow(10,i/2))) && (n<(pow(10,i/2)))) && (l<=n))
    {
    j=0,k=0,f=0;
    c=l;
    while (l>=1)
    {
    s[j]= (l%10);
    ++j;
    l/=10;
    }
    d=n;
    while (n>=1)
    {
    s[j]= (n%10);
    ++j;
    n/=10;
    }
    sort(s,i);
    for (e=0;e<i;++e)
    {
    if (p[e]==s[e])
    ++f;
    }
    if (f==i)
    {
    if (g==1)
    {
    printf("\nJesus ........ing Christ! This is a goddmaned Vampire Number!\n");
    printf("\n%ld = ",b);
    printf("(%ld*%ld) ",c,d);
    --g, ++t;
    }
    else
    printf("= (%ld*%ld) ",c,d);
    ++t;
    }
    }
    }
    }
    }
    if ((t==0) && (i%2==0))
    printf("\nSorry dude. This ain't a Vampire Number!\n");
    else
    {
    if (t>2)
    printf("\n\nIt has %ld pairs of fangs.",t-1);
    if (t==2)
    printf("\n\nIt has 1 pair of fangs.");
    }
    }
    void sort(long int *z,long int h)
    {
    	long int u=h-1;
    while (u>=0)
    {
    for(h=0;h<=(u-1);++h)
    {
    if (z[h]<=z[h+1])
    swap(&z[h],&z[h+1]);
    else
    continue;
    }
    --u;
    }
    }
    void swap(long int *x,long int *y)
    {
    	long int t;
    t=*x;
    *x=*y;
    *y=t;
    }

  11. #11
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    While generous, you've needlessly bumped a 7 year old thread in the C++ forum with C code. Please read the Forum Guidelines before posting.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Typical crappy Turbo C code, no indentation, horrible variable names, implicit return from main, seven years too late.

    FAIL.

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    7 Year bump!

    Well I'll do the honours and drive a steak through this thread's heart! (Gotta be a candidate for pun of the day...)

    Closed

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If only you knew the difference between "steak" and "stake"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793


    ...still funny!

Popular pages Recent additions subscribe to a feed