Created
November 24, 2012 04:43
-
-
Save sl8r000/4138422 to your computer and use it in GitHub Desktop.
Simple Markov
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
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