Home Forums SQL Server 2008 SQL Server 2008 - General Puzzle : Generating two unique numbers from an array of numbers (repetation not allowed) RE: Puzzle : Generating two unique numbers from an array of numbers (repetation not allowed)

  • Luis Cazares (9/12/2012)


    Eugene Elutin (9/12/2012)


    You don't really need last join as the last digit of the second number can only be '3'

    Wouldn't that be cheating?

    Because that way I can get the best performance

    SELECT 41286 num1,

    7953 num2

    I had my solution that was very similar to yours (again) but using the different(<>) operators instead of the NOT IN.

    However, a better performance would be using the best datatype for the digits (char) since the beginning avoiding additional conversions.

    (emphasis added)

    That's why I did mine that way. Makes the concatenation, etc., more efficient, at the cost of the final Where clause being slightly more costly.

    I also kept the rules for what fixed numbers go in what columns in the Where clause, instead of in the various From objects, because that way it can be modified for related queries more easily. If, for example, the puzzle were modified to "second number must start with '79'" instead of "first number must start with '4' and end with '6'", then a simple modification of the Where clause would make my version work.

    For related puzzles, you could assign a parameter to each column. If not null, then fixed value for that column. Final value could also be a parameter.

    And, yeah, I really do think extensibility like that with every piece of code I write.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon