Jump to content

Programming Puzzles [earn reputation]

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
46 replies to this topic

#1
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Posted Image


One of the approaches to understanding a large amount of data is to characterize it using few numbers. Statistics such as minimum, maximum, and vario0us kinds of averages tell you global properties. Sometimes they are enough to reveal information about individuals. This is why databases that give only statistical information are an issue for privacy advocates: Enough statistical questions can reveal personal data.

Consider a simple game between a questioner Quentin and a responder Rosalba. Quentin can ask only about global properties of a group of numbers, e.g, are they all whole numbers, are they distinct, and the statistics -- mean, median, minimum, and maximum.

Rosalba always tells the truth. She may refuse to anser, however, if she knows the answer may divulge all the numbers. As we'll see, the refusal to answer may itself divulge all the numbers. Sometimes, she will volunteer information just for the fun of it.


Rosalba: "I have five integers that may or may not be distinct."
Quentin: "What is the minimum?"
Rosalba: "20."
Quentin: "Whic of these would not allow me to infer all their values: number distinct, mean, maximum, or median?"
Rosalba: "Only the median."
Quentin: "Great. I know the numbers."

What are the numbers?

The winner will receive 20 reputation points.

Edited by John, 02 August 2008 - 03:52 PM.


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Posted Image

1) I put two bullets in two adjacent chamber of a six shot revolver. I point it at your head and pull the trigger. Click. You are still alive. The chamber has advanced by one. I am prepared to try again. Is it better for you if I spin again or not before pulling the trigger a second time? Explain.
Winner: gaylo565
Answer: http://forum.codecal....html#post52005



2) Two kids love cake and math. For this reason, Jeremy convinces Marie to play the following game on two[ identical rectangular cakes chef John has prepared for them.

Jeremy will cut the first cake into two pieces, perhaps evenly, perhaps not. After seeing the cut, Marie will decide whether she will choose first or allow Jeremy to do so. If she goes first, she will take the larger piece. If she goes second, she can assume that Jeremy will take the larger piece.

Next, Jeremy will cut the second cake into two pieces (remember that one of the pieces can be very small if he so chooses). If Marie had chosen first for the first cake, then Jeremy gets to take the larger piece of the second cake. If Marie had chosen second for the first cake, then she gets to take the larger piece of the second cake.


Assuming each child will strive to get the most total cake possible, what is an optimal strategy for Jeremy?
Winner: MeTh0Dz
Answer: http://forum.codecal....html#post52223



3) Andrew, Carol, Jessica, Luke, and Tommy are setting around a circular table. Carol is 12 years older than her neighbor to the left. Tommy is five years older than his neighbor to the right. Jessica is 14 years older than her neighbor to the left. Luke is five years younger than his neighbor to the left. By age, from youngest to oldest, they are ordered as follows: Luke, Tommy, Andrew, Jessica, and Carol. Luke is 16 and Carol is 40. The total of the ages is 135. In which order are the people sitting (starting with Tommy and then proceeding in a clockwise order) and what are their ages?

Winner: zeroradius
Answer: http://forum.codecal....html#post52683

4) A certain number theorist has recently disappeared. His safe may contain papers that would lead police to this whereabouts. The trouble is that his safe will self-destruct if it is forced open. So we must infer the combination.

He has left a few hints. They involve pairs of numbers. Each pair, p and q, has product (p x q), a greatest common divisor [gcd(p,q)], and a least common multiple [lcm(p,q)].

Consider, for example, p=10 and q=25. The greatest common divisor gcd(p,q)=5., because both 10 and 25 are divisible by 5, but not any number greater than 5. ("Divisible by" always implies a zero remainder.) The least common multiple lcm(p,q)=50, because 50 is divisible by 10 and by 25, but no positive number less than 50 is divisible by both 10 and 25. So the greatest common divisor has all prime factors in common to p and q, in this case 5 alone. The least common multiple has the prime factors contained by either, in this case 2, 5, and 5

The number theorist has left hints obeying the following rules:
i) These hints concern pairs of positive whole numbers p and q. For every pair, p <= q.
ii) Each of p and q has two digits (i.e, between 10 and 99 inclusive).

Suppose I tell you that q = 18, p is unknown, but gcd(p,q) = 6 and lcm(p,q) = 36. What is p?
Winner: zeroradius

Edited by John, 02 August 2008 - 03:52 PM.


#3
MeTh0Dz

MeTh0Dz

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,119 posts
Assuming that I don't want to die (lol which is true), it is better for me if you spin the chamber again. This is because if you don't spin the chamber there is a 2 in 5 chance that there is going to be a bullet, 40 percent. However, if you spin the chamber my chances return to 2 in 6, 33 percent. I am 7 percent less likely to die.

I think that's correct.

#4
Guest_Jaan_*

Guest_Jaan_*
  • Guests
goddamn.. i'm not soo smart to answer to this..

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Winged, do you agree or disagree?

#6
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
because the two bullets are in adjacent chambers you are better off not spinning the gun again. You know that the click was one of the 4 remaining empty chambers, and because only 1 of the 4 remaining chambers is the one before the 2 occupied chambers, your chances that the next shot is a bullet is only 1/4 where if you spin again your chances are 2/6 or 1/3 and not as good:) Hows that sound John?

Edited by gaylo565, 07 July 2008 - 07:42 AM.


#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
gaylo565 is correct. The fact that the bullets are adjacent is significant.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Yep. Let E represent an empty chamber and B represent a chamber with a bullet, the first shot has 6 possible combinations:

BBEEEE
EBBEEE
EEBBEE
EEEBBE
EEEEBB
BEEEEB

Giving these combinations, you can see that on the first shot you have a 33% chance to die. However, you are still alive which means we must have received one of these combinations:

EBBEEE
EEBBEE
EEEBBE
EEEEBB

From these, you can see there is only one case out of four in which you will die on the second shot giving you a 75% chance to live as opposed to a 66% chance if you spun the barrel.

Check my first post for a new puzzle.

#9
MeTh0Dz

MeTh0Dz

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,119 posts
Okay let's see if I have better luck with this puzzle...

Jeremy should cut the first cake unevenly, we'll say into one third of the cake and two thirds of the cake. If Maria allows him to go first, take the bigger piece obviously, otherwise she will have the bigger piece. Now, if Jeremy got the bigger piece of cake, he should cut the second one evenly. If he got the smaller piece, he should cut this one unevenly too, we'll say into one fourth of the cake and three fourths of the cake. Jeremy should then take the piece of cake that is three fourths of it.

This strategy will ensure that Jeremy gets more cake than Maria, however I didn't figure out the exact optimal amounts he should cut it in, because I guess I'm too lazy lol. However this is an effective strategy.

#10
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
I think you are on the right track.

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
MeTh0Dz: I think there's something missing... does each person cut once, or how exactly is the process of cutting/choosing determined?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
Guest_Jordan_*

Guest_Jordan_*
  • Guests

MeTh0Dz said:

Okay let's see if I have better luck with this puzzle...

Jeremy should cut the first cake unevenly, we'll say into one third of the cake and two thirds of the cake. If Maria allows him to go first, take the bigger piece obviously, otherwise she will have the bigger piece. Now, if Jeremy got the bigger piece of cake, he should cut the second one evenly. If he got the smaller piece, he should cut this one unevenly too, we'll say into one fourth of the cake and three fourths of the cake. Jeremy should then take the piece of cake that is three fourths of it.

This strategy will ensure that Jeremy gets more cake than Maria, however I didn't figure out the exact optimal amounts he should cut it in, because I guess I'm too lazy lol. However this is an effective strategy.

I guessed this and John said it was correct (although I wasn't allowed to post). I don't believe you need the exact figures but I used 60/40% on the first cut and as much as he wanted on the second cut if she choose first (99/1%) or 50/50% otherwise.