Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In class we have a big trouble, how can we get the first "n" vampire numbers, we're working on oracle SQL but in my case I am totally lost, how can i do a query to get it.

A "vampire number" is a number with an even number of digits, and half the digits (in any order) can be multiplied by the other half of the digits (in any order) to be equal to that number.

For example, 1260 is a vampire number because it can be broken in half, and the two halves rearranged (21 and 60) can be multiplied together to make 1260

share|improve this question
Not everyone will know what a "vampire" number is. Can you perhaps explain? –  Bill Michell Feb 27 '12 at 16:41
Why is Oracle needed to do this? Does the database have a list of Vampire Numbers already pre-computed? –  Ivan Feb 27 '12 at 16:42
Vampire numbers? You mean numbers that drain your blood? Or perhaps they prey on other numbers.... –  Rachel Feb 27 '12 at 16:44
what is in the DB? perhaps you should ask your tutor what you are meant to do –  jk. Feb 27 '12 at 16:50
You got your explanation somewhat wrong. The "halves" don't have to be in the order of the original - 21 * 60 == 1260. –  Oded Feb 27 '12 at 16:51
show 2 more comments

closed as too localized by MichaelT, gnat, Martijn Pieters, Mark Booth, psr Mar 7 '13 at 18:40

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Personally I would put all the vampire numbers in a database table, and select the top N records from that table.

It would be far too slow to loop through every number and check if each one is a vampire number since they seem to be few and far between.

share|improve this answer
But that is not the Homework assignment... –  Morons Feb 27 '12 at 17:16
@Morons I don't supply homework assignment answers, but I will provide a practical solution to a theoretically real problem (although honestly, I don't see any way this could be used in a practical sense unless it's for a game or something) :) –  Rachel Feb 27 '12 at 17:26
I can see the game now: John Nash Vampire (Number) Hunter...I would buy it. –  Jetti Feb 27 '12 at 18:35
add comment

Ok, here's some pseudo-code:

      a := a_seq's element
      b := b_seq's element
      c := a * b
      a_seq := 0...infinity
      b_seq := 0...infinity
      a < b AND

I know this hardly has anything to do with SQL code, but it should get the idea across ;)

share|improve this answer
+1 for having the right pseudocode, although I still say something like this would take far too long to run, and definitely should not be run on a SQL server :) –  Rachel Feb 28 '12 at 13:53
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.