Go Down

Topic: Urgent help needed with bar puzzle (Read 5350 times) previous topic - next topic

AWOL

Is this an example of "Schrödinger's goat" ?  :D
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

TomGeorge

Hi guys, it is the "three doors"  I agree with Boffin1.
Does anyone watch MYTHBUSTERS they already proved it.
Google it.
Tom
Everything runs on smoke, let the smoke out, it stops running......VK3DMK

robtillaart

SImulation of the bargame

There are 2 players, one that sticks to its initial choice and one that changes.
Every game is played with the both so they get the same set of games and they both have the same initial choice.

Code: (experimental) [Select]

//
//    FILE: simuBarGame.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1
// PURPOSE: simulate ashtray game
//     URL: http://forum.arduino.cc/index.php?topic=182297.0
//
// Released to the public domain
//

unsigned long win1 = 0;
unsigned long win2 = 0;
unsigned long games = 0;
float ratio = 0.0;

void setup()
{
  Serial.begin(115200);
  Serial.println("Start ashtray game");
}

void loop()
{
  games++;
  int pos = random(3);  // position of coin
  int initialChoice = random(3);  // initial choice

  // NOT CHANGING PLAYER
  // straightforward
  if (pos == initialChoice) win1++;

  // CHANGING PLAYER
  // select one that is empty to turn
  int turn = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == pos) continue;
    if (i == initialChoice) continue;
    turn = i;
  }
  // change choice
  int newchoice = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == turn) continue;
    if (i == initialChoice) continue;
    newchoice = i;
  }
  if (pos == newchoice) win2++;

  ratio = (1.0 * win1)/win2;

  // DISPLAY
  Serial.print(games);
  Serial.print("\t");
  Serial.print(win1);
  Serial.print("\t");
  Serial.print(win2);
  Serial.print("\t");
  Serial.println(ratio, 4);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Boffin1

Nice sketch Rob

I have just stuck some names on the results for disbelievers :-)  :-

Code: [Select]

//    FILE: simuBarGame.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1
// PURPOSE: simulate ashtray game
//     URL: http://forum.arduino.cc/index.php?topic=182297.0
//
// Released to the public domain
//

unsigned long win1 = 0;
unsigned long win2 = 0;
unsigned long games = 0;
float ratio = 0.0;

void setup()
{
  Serial.begin(115200);
  Serial.println("Start ashtray game");
}

void loop()
{
  games++;
  int pos = random(3);  // position of coin
  int initialChoice = random(3);  // initial choice

  // NOT CHANGING PLAYER
  // straightforward
  if (pos == initialChoice) win1++;

  // CHANGING PLAYER
  // select one that is empty to turn
  int turn = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == pos) continue;
    if (i == initialChoice) continue;
    turn = i;
  }
  // change choice
  int newchoice = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == turn) continue;
    if (i == initialChoice) continue;
    newchoice = i;
  }
  if (pos == newchoice) win2++;

  ratio = (1.0 * win1)/win2;

  // DISPLAY
    Serial.print("games played =");
  Serial.print(games);
  Serial.print("\t");
  Serial.print("won by keeping =");
  Serial.print(win1);
  Serial.print("\t");
   Serial.print("won by changing =");
  Serial.print(win2);
  Serial.print("\t");
   Serial.print("ratio =");
  Serial.println(ratio, 4);
}

radman

@robtillaart I like your sketch too particulary the neat code section below. Though in the case of deciding which empty one to reveal you would be better to include a random element as well - not that it affects the outcome.

Code: [Select]
// select one that is empty to turn
  int turn = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == pos) continue;
    if (i == initialChoice) continue;
    turn = i;
  }

radman

Quote
Hey Radman,   have you any more of these conundrums ?

Not as good as this one. I think we will soon hear @flyboy's hand slapping his forehead when the krugerrand drops.

The novel that reminded me of the puzzle twists your mind even more;

A man knows his wife is cheating on him. He follows her and her lover to an hotel intending to catch them in flagrante delicto. He is unsure exactly which room they have gone into, it could be 401, 402, or 403. At random he picks room 401. Just as he is about to kick in the door a family come out of room 403. Waiting until the family has left he realises he now has a much better chance if he changes in mind and kicks in door 402 which he does revelaing the cheating couple.

Of course he might still have got it wrong but the odds were 2:3 they were in 402.

Boffin1


"The novel that reminded me of the puzzle twists your mind even more;"

I think its the same, but spiced up with a bit of sex instead of Krugerands or cars :-)

Room 401 still only had the original 1 in 3 chance .

radman

Quote
I think its the same


It is the same, but its more "real".
With the krugerrands and cars there is a person the barman or the game show host who knows what is under each ashtray or behind each door.

In the hotel situation nobody knows who is in the rooms. The man is just lucky that somebody comes out of a door other than the one he had chosen. Of course if somebody was going to come out of a door at that time the odds of it being a different door to the one he had chosen were 2:3  , so it was likely he was going to get the opportunity to change his mind   :)

Coding Badly

Why not write a small simulation with counters and random generator on Arduino to run it a few million times should converge to result ...


Like the one in Reply #20?   ;)

radman

@CodingBadly , sorry but the @robtillart simulation is neat, very easy to follow and agrees with the truth table.

Coding Badly


radman


...and agrees with the truth table.


Mine doesn't?


@CodingBadly I have a confession to make. I did not run your code on an Arduino, nor did I run @robtillaart's code either. I tried to play them in my brain. I am sure your code was excellent but my brain crashed during execution, however the other ran to completion giving the predicted result. That is good scientific method - making a prediction and then determining the results by experiment.

Upon reflection though and looking back at previous post I think actually your code would have agreed had my brain cell been able to cope?


So now ;    
Faites vos jeux messieurs, dames

Go Up