Thread: Riddle Thread

  1. #31
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Hey that's pretty cool, though. Nice one.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #32
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895

    Riddle #3: three dwarfs, two paths, one life

    Giant In the Playground Games

    That's all I'll say.
    Last edited by CornedBee; 03-28-2009 at 11:42 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #33
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640

    Riddle #3: three dwarfs, two paths, one life

    There's a whole book of these problem called Knights and Knaves, something like this:
    Knights and Knaves: Knights and Knaves Logic Puzzle

    Knights always tell the truth and Knaves always lie. There was a second book about Humans and Vampires. Humans always tell the truth, vampires always lie, insane humans think they are telling the truth but lie, and insane vampires think they are lying but always tell the truth. Then there's a bunch of riddles of this sort.

    If you like this, also check out The Puzzling Adventures of Dr. Ecco
    Last edited by CornedBee; 03-28-2009 at 11:42 AM.

  4. #34
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    Number theory in 21 minutes

    Its faster to just check if a number, modulo 6469693230 has a prime remainder, since all prime numbers do.
    Last edited by CornedBee; 03-28-2009 at 11:42 AM.

  5. #35
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Number theory in 21 minutes

    The greatest common factor explanation of this is great
    Last edited by CornedBee; 03-28-2009 at 11:43 AM.

  6. #36
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Number theory in 21 minutes

    >> Its faster to just check if a number, modulo 6469693230 has a prime remainder, since all prime numbers do.

    Are you sure about that? Can you elaborate?
    Last edited by CornedBee; 03-28-2009 at 11:43 AM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #37
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312

    Riddle #3: three dwarfs, two paths, one life

    Ok, just to bring this to an end:

    First, you ask a random dwarf: "Who of your brothers lies more often?"

    If you happen to ask A, he will correctly point to C.
    If you happen to ask B, he will incorrectly point to C.
    If you happen to ask C, he will randomly point to either A or B.

    In either case, the dwarf not asked and not pointed to is not C.

    Ask this dwarf the following question: "Which path would the dwarf suggest who is the exact opposite of you?"

    If you ask A, he will tell the truth and provide you with the path that B would've suggested, i.e. the wrong path.
    If you ask B, he will lie and provide you with the path that A would'nt have suggested, i.e. the wrong path.

    So you take the other path.

    Greets,
    Philip
    Last edited by CornedBee; 03-28-2009 at 11:43 AM.
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  8. #38
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413

    Riddle #3: three dwarfs, two paths, one life

    hmm... but that seems to assume that the dwarves are benevolent. If they are (or more accurately, could be) malicious, then you have to phrase that second question more explicitly to your advantage.
    Last edited by CornedBee; 03-28-2009 at 11:44 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #39
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312

    Riddle #5: more dwarfs

    There are seven dwarfs, each one wearing a unique hat. A wind blows off the hats. The dwarfs start running after their hats and each dwarf puts on the first hat that he manages to catch. Eventually every dwarf has a hat again.

    What is the probability that exactly six dwarfs are wearing their own hat now?

    Greets,
    Philip
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  10. #40
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312

    Riddle #3: three dwarfs, two paths, one life

    Quote Originally Posted by laserlight View Post
    hmm... but that seems to assume that the dwarves are benevolent. If they are (or more accurately, could be) malicious, then you have to phrase that second question more explicitly to your advantage.
    Right. I already had several discussions about that. The problem arises due to the inexactness of most natural languages. The most obvious solution is to ask a more concise (and more awful) question. Personally, I prefer adding the proposition to the riddle that the dwarfs are benevolent. I didn't do it in the first place because it only distracts from the intended solution, but it's good that you pointed it out.

    Greets,
    Philip
    Last edited by CornedBee; 03-28-2009 at 11:44 AM.
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  11. #41
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413

    Riddle #3: three dwarfs, two paths, one life

    Quote Originally Posted by Snafuist
    The problem arises due to the inexactness of most natural languages.
    I don't think so. I think that it is merely an unstated assumption. I wanted to propose the solution of just capturing the dwarves and dragging them in a direction to see their response, but then I realised that I could not be sure that the dwarves were not so bored with their existence that they intended suicide, hence I would have to ask them questions anyway
    Last edited by CornedBee; 03-28-2009 at 11:44 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #42
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312

    Riddle #4: if-statement considered harmful

    Oops, I skipped #4, so here it is.

    Consider the following program:

    Code:
    int cmp(int a, int b)
    {
            if(a > b) {
                    return 1;
            } else if(a < b) {
                    return -1;
            } else {
                    return 0;
            }
    }
    Can you come up with an implementation that doesn't use conditionals, i.e. if, for, while, switch?

    Greets,
    Philip
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  13. #43
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413

    Riddle #4: if-statement considered harmful

    I presume that includes ternary operator, and that this is either C or C++?
    Last edited by CornedBee; 03-28-2009 at 11:45 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #44
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677

    Riddle #4: if-statement considered harmful

    Code:
    return (a >b)?1:(a<b)?-1:0;
    --
    Mats
    Last edited by CornedBee; 03-28-2009 at 11:45 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #45
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336

    Riddle #5: more dwarfs

    I would say that equals (6!/(6*5!))-1.
    Last edited by CornedBee; 03-28-2009 at 11:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM
  2. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  3. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 08:50 AM
  4. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 11:34 PM
  5. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM