• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jun 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import sys
2.
3.
4. def get_bit(bits, i):
5.     if 0 <= i < len(bits):
6.         return int(bits[i])
7.     else:
8.         return 0
9.
10.
11. def get_new_state(old_state):
12.     new_state = []
13.     for index in range(len(old_state)):
14.         if (get_bit(old_state, index-1) == 0 and get_bit(old_state, index+1) == 0) or (get_bit(old_state, index-1) == 1 and get_bit(old_state, index+1) == 1):
15.             new_state.append(0)
16.         elif(get_bit(old_state, index-1) == 0 and get_bit(old_state, index+1) == 1) or (get_bit(old_state, index-1) == 1 and get_bit(old_state, index+1) == 0):
17.             new_state.append(1)
18.     return new_state
19.
20.
22.     if set(state).pop() == "1":
23.         return False
24.     elif set(state).pop() == 1:
25.         return False
26.     elif len(set(state)) == 1:
27.         return True
28.     else:
29.         return False
30.
31.
32. def foresee_fate(state):
33.     seen = []
34.     while True:
36.             return False
37.         if state in seen:
38.             return True
39.         seen.append(state)
40.         state = get_new_state(state)
41.
42.