Created
November 3, 2020 10:59
-
-
Save JonCB/d582582d43ad60242dc47355ed86125d to your computer and use it in GitHub Desktop.
Sleeping Julia Py version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python version of Sleeping Julia for formatting help | |
# Copied from https://www.lesswrong.com/posts/Y6TtPfcKiHjK9Bmoa/sleeping-julia-empirical-support-for-thirder-argument-in-the | |
import random | |
class SleepingBeautyExperiment: | |
def __init__(self): | |
self.wakeups = 0 | |
self.bets = { | |
'heads' : { 'win' : 0, 'loss' : 0}, | |
'tails' : { 'win' : 0, 'loss' : 0}, | |
} | |
def run(self, bet): | |
coin = ('heads', 'tails') | |
coin_toss = random.choice(coin) | |
win_or_loss = 'win' if coin_toss == bet else 'loss' | |
self.bets[bet][win_or_loss] += 1 | |
# Tuesday, in case of tails | |
if coin_toss == 'tails': | |
self.bets[bet][win_or_loss] += 1 | |
def repeat(self, bet, times): | |
for i in range(times): | |
self.run(bet) | |
def reset(self): | |
self.__init__() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I wish LessWrong were open source, I'd add a code highlighting feature myself.