Skip to content

Instantly share code, notes, and snippets.

@sl8r000
Created November 24, 2012 04:43
Show Gist options
  • Save sl8r000/4138422 to your computer and use it in GitHub Desktop.
Save sl8r000/4138422 to your computer and use it in GitHub Desktop.
Simple Markov
import sys
import random
if __name__ == "__main__":
state, num_steps = sys.argv[1], int(sys.argv[2])
count = dict()
count['a'], count['b'] = 0, 0
for i in range(num_steps):
count[state] += 1
flip = random.random()
if state == 'a' and flip <= 2.0/3:
state = 'b'
elif state == 'b' and flip <= 1.0/4:
state = 'a'
for x in count:
print x, count[x]/(1.0*num_steps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment