'===========================================================================
' Subject: VAMPIRE NUMBERS GENERATOR          Date: 07-17-99 (18:55)       
'  Author: Cheng Lee                          Code: QB, QBasic, PDS        
'  Origin: bjuice@newmail.net               Packet: ALGOR.ABC
'===========================================================================
'--------------------------------------------------------------------------
'Project Name: Vampire Numbers Generator
'Author: Cheng Lee
'Email: bjuice@newmail.net
'Date: July, 1999
'
'Description:
'
'When you multiply a pair of two digits number together and if the answer
'contains all the digits of the multiplied numbers then you have a vampire
'number e.g  15 x 93 = 1395  <= 1395 contains the digits 1,5,9 and 3.
'--------------------------------------------------------------------------

'The starting number
StartNum = 1009

'Create 2 arrays that will hold the answer of the current 2 digits
DIM Array1$(4)
DIM Array2$(4)

CLS
PRINT ".:. Vampire Numbers Generator .:."
PRINT

'A guarded loop that keeps going until StartNum reaches the very last
'2 digits e.g 9999
DO WHILE StartNum <> 9999

 'Increment StartNum by 1
 StartNum = StartNum + 1

 'Create a temporary variable that holds the result of numeric to
 'string conversion
 Temp1$ = STR$(StartNum)

 'Extract the 1st and 2nd 2 digits number
 FirstBit = VAL(LEFT$(Temp1$, 3))
 SecondBit = VAL(RIGHT$(Temp1$, 2))

 Answer = FirstBit * SecondBit

   IF Answer >= 1000 THEN

    'Create another temporary variable that holds the result of numeric
    'to string conversion
    Temp2$ = STR$(Answer)

    'Fill the arrays with each digit of the answer
    FOR i = 1 TO 4
     Array1$(i) = MID$(Temp1$, i + 1, 1)
     Array2$(i) = MID$(Temp2$, i + 1, 1)
    NEXT i

    'Bubble sort the arrays so that comparison can be made
    FOR j1 = 1 TO 4
     FOR j2 = j1 TO 4
      IF (VAL(Array1$(j1)) > VAL(Array1$(j2))) THEN SWAP Array1$(j1), Array1$(j2)
      IF (VAL(Array2$(j1)) > VAL(Array2$(j2))) THEN SWAP Array2$(j1), Array2$(j2)
     NEXT j2
    NEXT j1

    'Concantenate each index of the sorted array to a final string for
    'camparison
    Final1$ = Array1$(1) + Array1$(2) + Array1$(3) + Array1$(4)
    Final2$ = Array2$(1) + Array2$(2) + Array2$(3) + Array2$(4)

    'Check and see if both are the same and if so then display the vampire
    'number
    IF Final1$ = Final2$ THEN
     PRINT TAB(10); FirstBit; "x"; SecondBit; "="; Answer
    END IF

   END IF

LOOP
