Skip to content

Instantly share code, notes, and snippets.

@JonCB
Created November 3, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonCB/d582582d43ad60242dc47355ed86125d to your computer and use it in GitHub Desktop.
Save JonCB/d582582d43ad60242dc47355ed86125d to your computer and use it in GitHub Desktop.
Sleeping Julia Py version
# 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__()
@seisvelas
Copy link

Thanks! I wish LessWrong were open source, I'd add a code highlighting feature myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment