Who Works on What?

  • Comments posted to this topic are about the item Who Works on What?

  • Steve Jones - SSC Editor - Tuesday, August 21, 2018 9:12 PM

    Comments posted to this topic are about the item Who Works on What?

    Nice one Steve, just like making sense out of requirement documentation😀
    😎

  • Nice one - it's quite a tricky Einstein Riddle
    Needs an "X" on the form though

    Michael Gilchrist
    Database Specialist
    There are 10 types of people in the world, those who understand binary and those that don't. 😀

  • Hang on - was it a hint to provide a SQL based solution, I can see the where clause already 😎

    Michael Gilchrist
    Database Specialist
    There are 10 types of people in the world, those who understand binary and those that don't. 😀

  • Haven't done of these since I was a kid, thanks! Enjoyed that 🙂

  • Luckily I already had my first cup of coffee on board before I tackled this.

  • I love it!!!

    Kindest Regards, Rod Connect with me on LinkedIn.

  • When should we expect an answer?

  • Apologies on the answer. My scheduling thing didn't quite work as expected.

    Answer here: http://www.sqlservercentral.com/articles/Logic+Puzzle/176523/

  • Steve Jones - SSC Editor - Wednesday, August 22, 2018 9:46 AM

    Apologies on the answer. My scheduling thing didn't quite work as expected.

    Answer here: http://www.sqlservercentral.com/articles/Logic+Puzzle/176523/

    As I said earlier, just like business requirements with all the implied ambiguity, this is not the only solution that fits the requirements 😉
    😎

    I found this one and another one, unfortunately forgot to safe it :pinch:

  • I enjoyed this one a lot.  Thanks for the fun challenge Steve!

  • Sack the new project manager because he was too lame to speak directly to the developers.

  • There may be a more elegant way of doing this, but given that SQL is declarative, we can just give all the information to the database engine and ask it to sort it out. It actually runs surprisingly fast.
    WITH post_its (post_it)
    AS
    (
        SELECT 'pink'
        UNION ALL SELECT 'brown'
        UNION ALL SELECT 'red'
        UNION ALL SELECT 'white'
        UNION ALL SELECT 'gray'
    ),
    drinks (drink)
    AS
    (
        SELECT 'tea'
        UNION ALL SELECT 'mountain dew'
        UNION ALL SELECT 'beer'
        UNION ALL SELECT 'water'
        UNION ALL SELECT 'coffee'
    ),
    languages (language)
    AS
    (
        SELECT 'T-SQL'
        UNION ALL SELECT 'C#'
        UNION ALL SELECT 'Javascript'
        UNION ALL SELECT 'PowerShell'
        UNION ALL SELECT 'HTML/CSS'
    ),
    combinations
    AS
    (
        SELECT *
        FROM post_its
            CROSS JOIN drinks
            CROSS JOIN languages
    )
    SELECT combinations_1.post_it AS post_it_1,
        combinations_1.drink AS drink_1,
        combinations_1.language AS language_1,
        combinations_2.post_it AS post_it_2,
        combinations_2.drink AS drink_2,
        combinations_2.language AS language_2,
        combinations_3.post_it AS post_it_3,
        combinations_3.drink AS drink_3,
        combinations_3.language AS language_3,
        combinations_4.post_it AS post_it_4,
        combinations_4.drink AS drink_4,
        combinations_4.language AS language_4,
        combinations_5.post_it AS post_it_5,
        combinations_5.drink AS drink_5,
        combinations_5.language AS language_5
    FROM combinations AS combinations_1
        CROSS JOIN combinations AS combinations_2
        CROSS JOIN combinations AS combinations_3
        CROSS JOIN combinations AS combinations_4
        CROSS JOIN combinations AS combinations_5
    WHERE combinations_1.post_it <> combinations_2.post_it
        AND combinations_1.drink <> combinations_2.drink
        AND combinations_1.language <> combinations_2.language
        AND combinations_1.post_it <> combinations_3.post_it
        AND combinations_1.drink <> combinations_3.drink
        AND combinations_1.language <> combinations_3.language
        AND combinations_1.post_it <> combinations_4.post_it
        AND combinations_1.drink <> combinations_4.drink
        AND combinations_1.language <> combinations_4.language
        AND combinations_1.post_it <> combinations_5.post_it
        AND combinations_1.drink <> combinations_5.drink
        AND combinations_1.language <> combinations_5.language
        AND combinations_2.post_it <> combinations_3.post_it
        AND combinations_2.drink <> combinations_3.drink
        AND combinations_2.language <> combinations_3.language
        AND combinations_2.post_it <> combinations_4.post_it
        AND combinations_2.drink <> combinations_4.drink
        AND combinations_2.language <> combinations_4.language
        AND combinations_2.post_it <> combinations_5.post_it
        AND combinations_2.drink <> combinations_5.drink
        AND combinations_2.language <> combinations_5.language
        AND combinations_3.post_it <> combinations_4.post_it
        AND combinations_3.drink <> combinations_4.drink
        AND combinations_3.language <> combinations_4.language
        AND combinations_3.post_it <> combinations_5.post_it
        AND combinations_3.drink <> combinations_5.drink
        AND combinations_3.language <> combinations_5.language
        AND combinations_4.post_it <> combinations_5.post_it
        AND combinations_4.drink <> combinations_5.drink
        AND combinations_4.language <> combinations_5.language
        AND ((combinations_1.post_it = 'pink' AND combinations_3.post_it = 'brown')
            OR (combinations_1.post_it = 'brown' AND combinations_3.post_it = 'pink')
            OR (combinations_2.post_it = 'pink' AND combinations_4.post_it = 'brown')
            OR (combinations_2.post_it = 'brown' AND combinations_4.post_it = 'pink')
            OR (combinations_5.post_it = 'pink' AND combinations_5.post_it = 'brown')
            OR (combinations_5.post_it = 'brown' AND combinations_5.post_it = 'pink')
            )
        AND ((combinations_1.language = 'C#' AND combinations_2.drink = 'mountain dew')
            OR (combinations_2.language = 'C#' AND combinations_3.drink = 'mountain dew')
            OR (combinations_3.language = 'C#' AND combinations_4.drink = 'mountain dew')
            OR (combinations_4.language = 'C#' AND combinations_5.drink = 'mountain dew')
            )
        AND ((combinations_1.language = 'T-SQL' AND combinations_2.post_it = 'red')
            OR (combinations_1.language = 'T-SQL' AND combinations_3.post_it = 'red')
            OR (combinations_1.language = 'T-SQL' AND combinations_4.post_it = 'red')
            OR (combinations_1.language = 'T-SQL' AND combinations_5.post_it = 'red')
            OR (combinations_2.language = 'T-SQL' AND combinations_3.post_it = 'red')
            OR (combinations_2.language = 'T-SQL' AND combinations_4.post_it = 'red')
            OR (combinations_2.language = 'T-SQL' AND combinations_5.post_it = 'red')
            OR (combinations_3.language = 'T-SQL' AND combinations_4.post_it = 'red')
            OR (combinations_3.language = 'T-SQL' AND combinations_5.post_it = 'red')
            OR (combinations_4.language = 'T-SQL' AND combinations_5.post_it = 'red')
            )
        AND combinations_2.drink <> 'mountain dew'
        AND ((combinations_1.language = 'Javascript' AND combinations_4.drink = 'tea')
            OR (combinations_1.drink = 'tea' AND combinations_4.language = 'Javascript')
            OR (combinations_2.language = 'Javascript' AND combinations_5.drink = 'tea')
            OR (combinations_2.drink = 'tea' AND combinations_5.drink = 'tea')
            )
        AND combinations_2.language = 'PowerShell'
        AND ((combinations_1.drink = 'beer' AND combinations_3.post_it = 'pink')
            OR (combinations_1.post_it = 'pink' AND combinations_3.drink = 'beer')
            OR (combinations_2.drink = 'beer' AND combinations_4.post_it = 'pink')
            OR (combinations_2.post_it = 'pink' AND combinations_4.drink = 'beer')
            OR (combinations_3.drink = 'beer' AND combinations_5.post_it = 'pink')
            OR (combinations_3.post_it = 'pink' AND combinations_5.drink = 'beer')
            )
        AND ((combinations_1.post_it = 'gray' AND combinations_2.language = 'PowerShell')
            OR (combinations_2.post_it = 'gray' AND combinations_3.language = 'PowerShell')
            OR (combinations_3.post_it = 'gray' AND combinations_4.language = 'PowerShell')
            OR (combinations_4.post_it = 'gray' AND combinations_5.language = 'PowerShell')
            )
        AND ((combinations_1.language = 'C#' AND combinations_4.language = 'Javascript')
            OR (combinations_1.language = 'Javascript' AND combinations_4.language = 'C#')
            OR (combinations_2.language = 'C#' AND combinations_5.language = 'Javascript')
            OR (combinations_2.language = 'Javascript' AND combinations_5.language = 'C#')
            )
        AND ((combinations_1.drink = 'tea' AND combinations_3.post_it = 'brown')
            OR (combinations_1.post_it = 'brown' AND combinations_3.drink = 'tea')
            OR (combinations_2.drink = 'tea' AND combinations_4.post_it = 'brown')
            OR (combinations_2.post_it = 'brown' AND combinations_4.drink = 'tea')
            OR (combinations_3.drink = 'tea' AND combinations_5.post_it = 'brown')
            OR (combinations_3.post_it = 'brown' AND combinations_5.drink = 'tea')
            )
        AND ((combinations_1.language = 'T-SQL' AND combinations_3.drink = 'coffee')
            OR (combinations_1.drink = 'coffee' AND combinations_3.language = 'T-SQL')
            OR (combinations_2.language = 'T-SQL' AND combinations_4.drink = 'coffee')
            OR (combinations_2.drink = 'coffee' AND combinations_4.language = 'T-SQL')
            OR (combinations_3.language = 'T-SQL' AND combinations_5.drink = 'coffee')
            OR (combinations_3.drink = 'coffee' AND combinations_5.language = 'T-SQL')
            );

    By the way, this seems to work with or without the penultimate clue.

  • It took me three tries to realized that "sits to the left of" is not "sits directly to the left of"...

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply