What Book Are You Reading at the Moment?
-
- Posts: 15157
- Joined: Wed Nov 30, 2016 9:47 am
Re: What Book Are You Reading at the Moment?
You've shot to a tie atop the leaderboard, StA, well done on the simulation code.
You've left just one player in the cellar struggling to maintain a 0.2.
:goteam: :drunk:
You've left just one player in the cellar struggling to maintain a 0.2.
:goteam: :drunk:
-
- Posts: 38685
- Joined: Wed Nov 30, 2016 5:59 pm
Re: What Book Are You Reading at the Moment?
Only one element left in the listSuburbanFarmer wrote: ↑Sat Jan 05, 2019 8:00 pmThe answer is there in your code. You instructed the computer to run a completely random second choice.Speaker to Animals wrote: ↑Sat Jan 05, 2019 12:23 pmWell, fuck. I still cannot believe it is true, but wrote it out myself.
Code: Select all
import random count_first_guess_correct = 0.0 count_second_guess_correct = 0.0 count_total_games_played = 0.0 def run_game (): cups = {1:0, 2:0, 3:0} keys = list(cups.keys()) # hide the prize in one of the three cups prize_key = random.choice(keys) cups[prize_key] = 1 random.shuffle(keys) # player chooses random cup first_choice = keys[0] # Overturn a cup not containing the prize and not chosen by player keys.remove(first_choice) if prize_key != first_choice: keys.remove(prize_key) overturned_cup = keys[0] keys.remove(overturned_cup) # player chooses other cup keys = list(cups.keys()) keys.remove(first_choice) keys.remove(overturned_cup) second_choice = random.choice(keys) #Sanity checks if first_choice == second_choice: print ("Error: first choice and second choice are the same") elif prize_key == overturned_cup: print ("Error: prize key and overturned cup are the same") elif second_choice == overturned_cup: print ("Error: second choice and overturned cup are the same") if prize_key == second_choice: return 1 else: return 0 for n in range (0,10000): outcome = run_game() if outcome == 1: count_second_guess_correct = count_second_guess_correct + 1.0 else: count_first_guess_correct = count_first_guess_correct + 1.0 count_total_games_played = count_total_games_played + 1.0 percent_first_guess_correct = count_first_guess_correct / count_total_games_played percent_second_guess_correct = count_second_guess_correct / count_total_games_played print ("percent first guess correct: " + str(percent_first_guess_correct)) print ("percent second guess correct: " + str(percent_second_guess_correct)) print ("total games: " + str(count_total_games_played))
Output:
percent first guess correct: 0.3324
percent second guess correct: 0.6676
total games: 10000.0
Results are repeated numerous time. You actually have about 66% chance of getting the prize if you choose a second time.Effectively, you're counting the number of times that choosing between two remaining cups is correct/incorrect.second_choice = random.choice(keys)
Mandating that you switch on Choice 2 will yield an identical result to sticking with the cup chosen in Choice 1.
If you look at the bottom, the sanity check section shows you that it works out. I am not really a Python guy. Just used a quick hack.
I made it more clear instead of fucking around with the random package.
Code: Select all
# player chooses other cup
keys = list(cups.keys())
keys.remove(first_choice)
keys.remove(overturned_cup)
second_choice = keys[0]
percent first guess correct: 0.3286
percent second guess correct: 0.6714
total games: 10000.0
-
- Posts: 25279
- Joined: Wed Nov 30, 2016 6:50 am
- Location: Ohio
Re: What Book Are You Reading at the Moment?
You’ve proven that telling the computer to select between 3 cups, with one known wron will yield success 2/3 of the time.
-
- Posts: 38685
- Joined: Wed Nov 30, 2016 5:59 pm
Re: What Book Are You Reading at the Moment?
uh.. no.SuburbanFarmer wrote: ↑Sun Jan 06, 2019 9:01 amYou’ve proven that telling the computer to select between 3 cups, with one known wron will yield success 2/3 of the time.
I fill a list with three cups. I remove two cups (overturned cup and first choice cup). Only one cup remains in the list..
-
- Posts: 25279
- Joined: Wed Nov 30, 2016 6:50 am
- Location: Ohio
Re: What Book Are You Reading at the Moment?
That’s even worse.Speaker to Animals wrote: ↑Sun Jan 06, 2019 10:29 amuh.. no.SuburbanFarmer wrote: ↑Sun Jan 06, 2019 9:01 amYou’ve proven that telling the computer to select between 3 cups, with one known wron will yield success 2/3 of the time.
I fill a list with three cups. I remove two cups (overturned cup and first choice cup). Only one cup remains in the list..
-
- Posts: 38685
- Joined: Wed Nov 30, 2016 5:59 pm
Re: What Book Are You Reading at the Moment?
LMFAOSuburbanFarmer wrote: ↑Sun Jan 06, 2019 1:20 pmThat’s even worse.Speaker to Animals wrote: ↑Sun Jan 06, 2019 10:29 amuh.. no.SuburbanFarmer wrote: ↑Sun Jan 06, 2019 9:01 amYou’ve proven that telling the computer to select between 3 cups, with one known wron will yield success 2/3 of the time.
I fill a list with three cups. I remove two cups (overturned cup and first choice cup). Only one cup remains in the list..
-
- Posts: 25279
- Joined: Wed Nov 30, 2016 6:50 am
- Location: Ohio
Re: What Book Are You Reading at the Moment?
Whatevs, bud. I can’t force you to think.
-
- Posts: 38685
- Joined: Wed Nov 30, 2016 5:59 pm
Re: What Book Are You Reading at the Moment?
I create a list:
cups = [A, B, C]
I remove item A from the list:
del[A]
cups => [B, C]
I remove item C from the list:
del[C]
cups => [C]
What happens when I then write:
cups[0]
???
-
- Posts: 15157
- Joined: Wed Nov 30, 2016 9:47 am
Re: What Book Are You Reading at the Moment?
Flounder may be more of a Hollywood Squares guy.
-
- Posts: 38685
- Joined: Wed Nov 30, 2016 5:59 pm
Re: What Book Are You Reading at the Moment?
More python fun..
Output:
['C']
this is the only item in the list you dumbass: C
Code: Select all
cup_A = 'A'
cup_B = 'B'
cup_C = 'C'
cups = [cup_A, cup_B, cup_C]
cups.remove(cup_A)
cups.remove(cup_B)
print(cups)
print("this is the only item in the list you dumbass: " + cups[0])
['C']
this is the only item in the list you dumbass: C