Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / The most evil riddle in the world.

Author
Message
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 21st Mar 2004 11:16
I've just heard this one recently and it is driving me bonkers.

Okay, here it goes.

Its the last round of a game show. You have to choose between three doors labeled One, Two, and Three. Behind each door is a prize. Now two of the doors contain goats while one of the doors contains a brand new car.

Your asked to choose a door number. Lets say you choose 1. The Host then reveals a door other than the one that you choose, lets say that it is door number 0, and it has a goat behind it. You are then asked if you would like to change your choice to number 2 or stick with number 1.

Now the riddle is, does this make a difference? Should you change your answer or stick with it?

I really hate the answer to this one and didn't believe it until I worked out some code to try to disprove it, but wound up proving it in the process. I think. Attached in the source box is the answer and the code that I used to test it. Take a look after you decided you know what the answer is and run the code. You'll be amazed.
AnDrEy
20
Years of Service
User Offline
Joined: 11th Jan 2004
Location: In Da Club
Posted: 21st Mar 2004 12:19 Edited at: 21st Mar 2004 12:20
hmmm...... souce code button?
*looks around
what source code button?

00-----====JaCkPoT====-----00
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 21st Mar 2004 13:20
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 21st Mar 2004 13:55
so what was the answer? player 2 wins nearly double player 1 everytime does that prove that changing your guess gives you a higher chance of winning? how does that work?

In the beginning, the universe was created...
This made alot of people very angry and it has been widely regarded as a bad idea...
Visit http://redeye.dbspot.com
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Mar 2004 14:20
Err, so basically there are 3 doors, 2 of them have goats behind them and 1 has a new car. The probability is always the same 1/3. The host eliminates one door by showing it has a goat behind it. Probability goes down to 1/2. It makes no difference at all. There's the same chance there will be a car behind yours as the other.


"Computers are useless they can only give you answers."
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Mar 2004 14:20
Changing your answer is supposed to give you more chance of winning, but I have never managed to understand why. I have a book about it which explains it, but it still seems wrong to me. Actually it must be wrong.

Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Mar 2004 14:33 Edited at: 21st Mar 2004 14:38
It's because if you picked one of the wrong ones, they eliminate the other wrong one, meaning if you change your answer, it will be the right one. And since there's twice the chance of picking the wrong (2 doors are bad, 1 is good), that means there's twice the chance of it being right if you switch. Hence the 2/3 probability or 66% of getting the car.

Look at it like this, consider door 3 is the winning door.

You pick 1. They eliminate 2. You switch to 3. You win.
You pick 2. They eliminate 1. You switch to 3. You win.
You pick 3. They eliminate 1 or 2. You switch to 2 or 1. You lose.

If you stayed:

You pick 1. They eliminate 2. You stay on 1. You lose
You pick 2. They eliminate 1. You stay on 2. You lose
You pick 3. They eliminate 1 or 2. You stay on 3. You win.

Edit: Those are all the outcomes you can get. If you change Door 1 to the winning door then the results will be the same anyway.


"Computers are useless they can only give you answers."
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 21st Mar 2004 14:35
3 doors, one option or // 3 to 1 or 33.33333333333333%

then it changes from

2doors one option or // 2 to 1 or 50.000000000000000000%



probability links
http://directory.google.com/Top/Science/Math/Probability/?tc=1


laymans probability
http://www.peterwebb.co.uk/probability.htm#mutual


nuclear glory
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 21st Mar 2004 14:50 Edited at: 21st Mar 2004 14:57
This may be based from the fact that you're first selection was base on a 1/3 probability and therefore has a lower overall chance of being correct (because it was chosen out of 3 options). Once it drops to two options, the probability increases (if you make a new selection) because you are now making a new selection from a 1/2 probability. This is based on the fact that your first chance has a low probability of being correct (as it came from 1 out of 3 options).

This is borderline vodoo math mind you.

There is a statement that could be clarified though:

"Switching to the other door increases your chances of winning to 66%."

66% chance of winning from what start point? Before the first door is selected or after?


The math probably works like this.

originalProbability = 0.33
numOfNewChoices = 2
chanceOfWinning = originalProbability * numOfNewChoices

Base on the probability being calculated at the start of the game before any choices were actually made.

Lead Programmer/Director
Powerful Collision DLL for DBPro and DBC: http://www.nuclearglory.com
nuclear glory
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 21st Mar 2004 15:02 Edited at: 21st Mar 2004 15:07
ROFL

Or it probably works like this:

original probability = 0.33
probability increase = original probability * 0.66
final probability = original probability + probability increase

LOL, this comes down to "what is 66% of 33%?"

Working out the math:

probability increase = 0.33 * 0.66 (answer is: 0.2178)
final probability = 0.33 + probability increase (answer is: 0.5478)

Error margin because chances are actually 33.3333% repeating.


They aren't looking for the final probability. They're looking for the "probability increase". It's a trick question.

Lead Programmer/Director
Powerful Collision DLL for DBPro and DBC: http://www.nuclearglory.com
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Mar 2004 15:12
What in lords name are you talking about? They want to know if you should switch your answer or not, and this is proven by the final probability (which is 66% chance of getting it right if you switch). There's no trick, there's no probability increase rubbish in the question. I thought I explained the logic behind it quite clearly in my last post. Guess not.


"Computers are useless they can only give you answers."
nuclear glory
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 21st Mar 2004 15:17 Edited at: 21st Mar 2004 15:27
Hey hey, can't I have a go at this? lol.

My first answer is geared mathematically more towards yours Exeat. I'm just working it out with numbers.

We would need the exact wording of the riddle. If it says "your chances increase by 66%" that is different than "your chances increase to 66%".

Like a bad game of telephone.

A probability increase of 66% leaves you with close to a 50% chance.

You didn't expect me to stay out of a math riddle did you? It's like bait.

I'll be back later to see if anyone cracked it

Lead Programmer/Director
Powerful Collision DLL for DBPro and DBC: http://www.nuclearglory.com
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 21st Mar 2004 16:40 Edited at: 21st Mar 2004 16:42
You should change.
You are more likely to get a goat on the first guess.

If all goes to plan:-

- Pick door
- Get goat
- Goat removed
- Change to car
- Run over animals

(Last part optional)

P.S. I thought the most evil riddle was Fermat's Last Theorem


Coming Soon...
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 21st Mar 2004 17:39 Edited at: 21st Mar 2004 17:42
whats fermat's last theorum then?
*edit, infact don't tell me, just searched google, looked at the first link and realised i didn't want to do/learn/think about maths on a sunday, apparently its got something to do with the area of a triangle not being a square...

In the beginning, the universe was created...
This made alot of people very angry and it has been widely regarded as a bad idea...
Visit http://redeye.dbspot.com
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 21st Mar 2004 18:16
Exeat explained it quite well actually
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 21st Mar 2004 19:25 Edited at: 21st Mar 2004 19:26
Fermat's Last Theorem is that there are no whole number solutions for an equation like -

a^3 + b^3 = c^3

ie. No two cube numbers (1,8,27,64 ....) can add up to a cube number. This is hard to believe because there are an infinite number of cube numbers and an infinite number of solutions for the similiar Pythagoras's theorem (a^2 + b^2 = c^2 - 3,4,5 for example)

In fact, it's not just for cube numbers, but any power bigger than two.

It's so simple to understand yet probably the hardest mathmatical problem to prove. It was only proved in 1996 - the proof is 150 pages long.


Coming Soon...
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Mar 2004 19:50
I don't care what the maths says, my computer program says that there is no difference. Run this. If it takes ages, you might need to lower the Amount, but I can't see any significant difference.



Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 21st Mar 2004 19:50 Edited at: 21st Mar 2004 19:54
yes Exeat explained well

if you pick 1 of 3 doors you got 33% chance of getting car, therefore there is 66% of not getting car. So 66% of the time the other doors contain goat & car - they gotta show you goat, so 66% of time they leave door with car. So if you always change then you pick car 66% of time.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Mar 2004 20:28
@Neophyte I ran your code and I got zero wins for player 2, and that's impossible. Something is wrong with it somewhere.

the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 21st Mar 2004 20:42 Edited at: 21st Mar 2004 21:04
edit:
Try this code


Look at it this way. You have to guess a random number between 1 and 3, you will be wrong 66% or 2/3rds of the time.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Mar 2004 21:18 Edited at: 21st Mar 2004 21:30
That's not what the topic is about. It's about having a second 50/50 choice. I don't think that your code shows this, although I am so confused that it might.

Read this link!

http://mathworld.wolfram.com/MontyHallProblem.html

the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 21st Mar 2004 21:31 Edited at: 21st Mar 2004 21:32
Obviously it's susposed to trick you.
There are three doors, one with a prize, pick one.
(guess a number between one and three 1/3 chance of getting it)

They remove one of the incorrect doors and ask if you want to swap to the other remaining door.
(effectifly asking you if you guessed the number correctly, 2/3 chance you didn't)
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Mar 2004 21:40
Yes that is all very clear, but why does swapping your original choice improve your chances of winning according to probability. It is actually agreed that it improves your chances of winning. Try reading it again.

Shadow
22
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 21st Mar 2004 21:42
Right, as I see it, the doors all have equal chances. 1/3 chance of getting it right. After one is removed, there are two choices, each with 1/2 chance. Whether it is the same choice as your original pick is irrelevant. Sticking is still a choice.
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 21st Mar 2004 22:49
it goes from 1/3 to 2/3 chance
Shadow
22
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 22nd Mar 2004 00:06
I get it now.
Night Giant
21
Years of Service
User Offline
Joined: 26th Jul 2003
Location:
Posted: 22nd Mar 2004 00:56
Quote: "Your asked to choose a door number. Lets say you choose 1. The Host then reveals a door other than the one that you choose, lets say that it is door number 0, and it has a goat behind it. You are then asked if you would like to change your choice to number 2 or stick with number 1."


ok, what i get from this part is that, after you pick a door, the host does not open that door but another door completely seperate from the three doors you could choose from (door 0). thus it does not make any difference at all, as door 0 is not available to be chosen.

oh, wow. insignificantpunks.cjb.net. we like orange treble clef notes, just for future reference.

no: website for progs yet.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 00:59 Edited at: 22nd Mar 2004 01:00
That sould be door 3. That's misleading. His computer program uses 0 as a choice. 0,1,2

Night Giant
21
Years of Service
User Offline
Joined: 26th Jul 2003
Location:
Posted: 22nd Mar 2004 01:01
ooh, ok, i get it now.

oh, wow. insignificantpunks.cjb.net. we like orange treble clef notes, just for future reference.

no: website for progs yet.
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 22nd Mar 2004 05:34
@Pincho Paxton

"I ran your code and I got zero wins for player 2, and that's impossible. Something is wrong with it somewhere."

It works just fine here. Perhaps you copied and pasted it wrong?
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 22nd Mar 2004 08:14
Neophyte's app works for me also. Pincho's program is wrong because it never eliminates one of the choices which is the whole reason for increasing the chance of probability if you swap. If a choice is never eliminated then the probability will always remain at 1/3 and hence why he got results for 33% for both his players.

The reasoning behind it is that there's a 2/3 chance of picking the incorrect door. And because they eliminate the other incorrect door (but not the one you chose), the only thing you can switch to is the correct one. This means that if you choose the wrong door first then swapping will mean you ALWAYS choose the correct door, and as previously stated, there's a higher chance of getting the wrong door in the first place.

Quote: "Hey hey, can't I have a go at this? lol."


Of course! I was just stating that the question wasn't asking for the probability increase, they were just asking wether it would be better to switch or not. And this is proven by showing the new probability of switching.


"Computers are useless they can only give you answers."
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Mar 2004 10:04
I argued for weeks with my boss over this one. He was unfortunately right, in that it does improve your chances.

It's not actually worth explaining, you need to sit face to face with someone, with a huge blackboard and abouit 3 hours to spare.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 22nd Mar 2004 10:10
No - it is very simple to explain.

You are more likely to pick a goat on the first go.
You switch to the car.
You win.

That is the most likely outcome.


Coming Soon...
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 22nd Mar 2004 10:14 Edited at: 22nd Mar 2004 10:16
This is not at all puzzeling, its just worded to trick you at first glance.

If you were told you can either pick one door or two doors then you'd pick two, because this gives you 66% chance. Swapping doors is EXACTLY the same as choosing 2 doors at the beggining.

EXACTLY the same.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 15:47 Edited at: 22nd Mar 2004 15:51
Oh I can see the problem with my code, I'll fix it.


Edit: No it actually skips the goat door already. So it does eliminate the goat door.

It chooses Goat + 1, so it's impossible to pick the goat door.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 15:58
Hey Neophyte's code always gives me zero for player 2??? What the heck??? How can it work on other computers??? Now I am completly confused. Somebody please try his code in DB Classic.

Pincho.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Mar 2004 19:29 Edited at: 22nd Mar 2004 19:29
Quote: "Swapping doors is EXACTLY the same as choosing 2 doors at the beggining."


Not really. You are only picking one door.

What you are doing is in effect:

1. Picking a door when you only have 1/3 chance of winning
2. Reducing the total number of doors to 2 by removing a wrong one.
3. Picking again, now you only have 2 doors to choose from.

Here's the freaky bit. At the last step, you have a 50/50 chance. The whole crux of the matter now lies in the fact that 50/50 is less likely to be wrong than the original 1/3 chance you had, thus swapping is best for you.

It's like saying you have more chance of guessing heads or tails if you flip the coin fewer times. It's not that you have more chance of getting it right, it's that you have less chance of getting it wrong...get it?

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 22nd Mar 2004 19:53
@Pincho Paxton

"Somebody please try his code in DB Classic."

That would be the problem. I wrote it in Pro and since I don't have Classic I can't tell how it would behave.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 20:10
Funny that it doesn't give me any errors, and all of the commands are in the DB Classic Help file. Very confusing.

the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 22nd Mar 2004 20:34
Quote: "Here's the freaky bit. At the last step, you have a 50/50 chance."


No at the last step you have a 1/3 chance of being right. Removing one of the options after you have made your choice does not alter the proberbility of your original choice.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 22nd Mar 2004 20:55
@ Batvink

There is no 50-50 choice - thats how the riddle tricks you.

You pick a door - you got 33% chance of being right
So there is 66% chance of one of vthe other 2 being right.

So when they open a goat door of the other 2 and you swap then your choice changes across to the other two the - 66% chance.

There is no 50-50 just 33-66.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 20:56
Well I am still having to say that my computer program doesn't show hardly any difference between switching, and sticking, and I can't find any errors in it.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Mar 2004 22:25
Quote: "There is no 50-50 choice - thats how the riddle tricks you"


Yes, there is.

One of the wrong doors is removed from the equation. Now you have two doors, one is wrong and one is right. That is a 50/50 chance. The first part of the process, if you are going by the law of probability, is irrelevant.

The answer as it is given assumes that probability is constant. That is, the odds don't change. The odds do change as soon as you remove one door. Now read my previous post and see if it makes more sense.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 22nd Mar 2004 23:37
Quote: "One of the wrong doors is removed from the equation. Now you have two doors, one is wrong and one is right. That is a 50/50 chance. The first part of the process, if you are going by the law of probability, is irrelevant."


No it is a 33/66 or 1 in 3 chance. The first part of the process is relevent. They are asking you to guess a number between 1 and 3. Then they ask you if you think you guessed correctly. 33% of the time you guessed corrrectly 66% of the time you didn't so if you swap you have a greater chance of being correct.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Mar 2004 00:28
Ahh, I have found the error in my program. The host of the show was taking the goat from any of the two doors, but that was allowing him to take the goat out of your chosen door. I have stopped him from doing that now. This gives me new figures...

Swap = 666699
stick = 334077

You should always swap doors!!!

Pincho.






dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 23rd Mar 2004 02:00 Edited at: 23rd Mar 2004 02:02
@the winch, your right you have 33% chance your choice is right and 66% chance of the other 2 doors beeing right,

but if you eliminate one of the wrong doors that you didnt choose you are left with 2 doors, your choice and the other door, since the other goat door was removed, so your left with either the goat and the car, how is that possibly 1 in 3 chance??

[edit]
and batvink is right the first door you pick is irrelevant, since its either a car or a goat, and they reveal the goat so it doesnt matter which door you choose there will allways be at least one goat left

Andy Igoe
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 23rd Mar 2004 02:06
I would stick because I already have a car.

Goats are currency in somes parts of the world.


God created the world in 7 days, but we're still waiting for the patch.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 23rd Mar 2004 02:11 Edited at: 23rd Mar 2004 02:15
if you pick a goat in the begining (66%) and switch at the end then you get a car...if you pick the CAR at the begining (33%) and switch at the end then you get a goat...SOOOOoooo ALWAYS SWITCH

[edit] this is what happens if you don't switch...
if you pick a goat (66%) and don't switch then you get a goat!
if you pick a car(33%) and don't switch then you get a car.

You know, when i see an old lady slip and fall on the side walk, my first instinct is to luagh, but then i think, what if i where an ant? and she fell on me, it just doesn't seem so funny anymore.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Mar 2004 02:15 Edited at: 23rd Mar 2004 02:18
Hey, I wrote this program for school. Always choose the other door. Your chances improve for a 33% chance to 66% chance, on average.
Here's my source code.

edit:
stupid code box wont display everything.

edit:
alright, these forum code boxes suck!




import java.awt.*;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.util.Random;


/**
* Application to simulate the game show "Let's Make a Deal".
* Based on a chosen strategy, the simulation will give the
* win percentage out of a given number of games played.
*
* @author Dustin Zimnox
* @version 2003-12-5
*/
public class gameshow extends JFrame
{
private Random r = new Random(); //used to get a random number
private int[] doors = {0,0,0}; //The 3 doors
private int strategy; //stores the strategy used
private int numberOfGames; //Number of games to play
private double winPercentage; //percentage of winning
private JTextField StrategyResultField = new JTextField("Strategy: ", 20);
private JTextField numberOfGamesResultField = new JTextField("Number of games played: ", 20);
private JTextField winPercentageResultField = new JTextField("Win percentage: ", 20);


public gameshow() //constructor
{
JPanel panel = new JPanel();
JLabel strategyLabel = new JLabel("Strategy(1-3)");
JLabel numberOfGamesLabel = new JLabel("How many games to play?");

final JTextField strategyField = new JTextField(2);
final JTextField numberOfGamesField = new JTextField(6);
final JButton playButton = new JButton("Play"); //the PLAY button
final JButton resetButton = new JButton("Reset"); //the RESET button


class playButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source == playButton) //if PLAY button is pressed
{
strategy = Integer.parseInt(strategyField.getText()); //get strategy chosen
numberOfGames = Integer.parseInt(numberOfGamesField.getText()); //get number of games to be played
winPercentage = runGame(strategy, numberOfGames); //run the game, get percentage of wins

//update text fields containing the results of the simulation
StrategyResultField.setText("Strategy: " + strategy);
numberOfGamesResultField.setText("Number of games played: " + numberOfGames);
winPercentageResultField.setText("Win percentage: " + winPercentage);
}
else if (source == resetButton) //if RESET button is pressed
{
//clear all text fields
strategyField.setText("");
numberOfGamesField.setText("");
StrategyResultField.setText("Strategy: ");
numberOfGamesResultField.setText("Number of games played: ");
winPercentageResultField.setText("Win percentage: ");
}
}//end actionPerformed() method
}//end playButtonListener class

ActionListener listener = new playButtonListener(); //button listener
playButton.addActionListener(listener);
resetButton.addActionListener(listener);


//add all the junk to the panel
panel.add(strategyLabel);
panel.add(strategyField);
panel.add(numberOfGamesLabel);
panel.add(numberOfGamesField);
panel.add(playButton);
panel.add(resetButton);
panel.add(StrategyResultField);
panel.add(numberOfGamesResultField);
panel.add(winPercentageResultField);

setContentPane(panel);

}//end constructor


/**
* Main method
*/
public static void main()
{
gameshow window = new gameshow();
window.pack();
window.setSize(new Dimension(350,300)); //set application window size
window.show();
}//end main() method


/**
* Game loop method.
* Simulates the game show
*/
public int runGame(int strat, int nOG) //strategy number and number of games to play
{
int initialChoice;
int newChoice=0; //new picked door number after strategy applied
int oldStrat = strat; //store original strategy, incase strategy 2 is used
int wins=0; //number of games won
double percent; //percentage of games won

for (int i=0; i<nOG; i++)
{

doors[0]=0; doors[1]=0; doors[2]=0; //reset doors array

doors[r.nextInt(3)] = 1; //randomly position a car behind a door
//A zero represents a goat, and 1 for car
initialChoice = r.nextInt(2); //randomly pick the first choice

if (strat == 2) //strategy 2, randomly chooses to use strategy 1 or 3
{
if (r.nextInt(1) == 0) strat = 1;
else strat = 3;
}

if (strat == 1) //strategy 1, stick with initial choice
{
if (doors[initialChoice] == 1) wins++;
}

else if (strat == 3) //strategy 3, always pick the other door
{
if (initialChoice == 0)
if (doors[1] == 0) newChoice = 2;
else newChoice = 1;
if (initialChoice == 1)
if (doors[0] == 0) newChoice = 2;
else newChoice = 0;
if (initialChoice == 2)
if (doors[0] == 0) newChoice = 1;
else newChoice = 0;

if (doors[newChoice] == 1) wins++;
}

strat = oldStrat; //reset strat with original strategy (for when strategy 2 is used)
}

//calculate win percentage value
percent = ((double)wins/(double)nOG)*100.0;


return (int)percent; //return win percentage value, cutting off fractions part
}// end runGame() method

}//end gameshow() class


"eureka" - Archimedes
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Mar 2004 02:18
Always switch.

It's like saying that there are 10 doors, and 1 of them has a car behind. You choose 1, and it is not likely to be the car. Then the host of the show opens 8 doors for you, and lets you see 8 goats. You are left with your first choice, and another choice. Obviously you didn't get the car first time, so you swap.

It is clearer now that my computer program works. I think you should all try to write you own computer programs.

Login to post a reply

Server time is: 2024-11-24 23:16:30
Your offset time is: 2024-11-24 23:16:30