Skip to content

Instantly share code, notes, and snippets.

@mofas
Created February 1, 2019 17:11
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 mofas/a8f9c2b4c3f691dee99a4b4e52d2fcc9 to your computer and use it in GitHub Desktop.
Save mofas/a8f9c2b4c3f691dee99a4b4e52d2fcc9 to your computer and use it in GitHub Desktop.
For eddie
def get_next_status_set(status):
ret = []
status_len = len(status)
for i in range(status_len - 1):
if status[i] == '1' and status[i + 1] == '0':
new = status[:]
new[i] = '0'
new[i + 1] = '1'
ret.append(''.join(new))
# handl the last case
if status[status_len - 1] == '1' and status[0] == '0':
new = status[:]
new[status_len - 1] = '0'
new[0] = '1'
ret.append(''.join(new))
return ret
# print(get_next_status([0, 1, 1, 0, 0, 1]))
init_status = ''.join(map(lambda x: str(x), [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]))
# print(init_status)
current = {init_status: 1.0}
next_status_set = {}
# print("step 0", current)
for i in range(20):
for status in current:
possibility = current[status]
new_status_set = get_next_status_set(list(status))
indivual_possibility = possibility / len(new_status_set)
for next_status in new_status_set:
# if existed
if next_status in next_status_set:
next_status_set[next_status] += indivual_possibility
else:
next_status_set[next_status] = indivual_possibility
print("step {}".format(i + 1), next_status_set)
current = next_status_set
next_status_set = {}
# # print("final result", len(current))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment