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.  
  21. def is_dead(state):
  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:
  35.         if is_dead(state):
  36.             return False
  37.         if state in seen:
  38.             return True
  39.         seen.append(state)
  40.         state = get_new_state(state)
  41.  
  42.  
  43. num_cases = int(sys.stdin.readline().strip())
  44. for i in range(num_cases):
  45.     cur_state = []
  46.     case = sys.stdin.readline().strip()
  47.     for char in case:
  48.         cur_state.append(char)
  49.     print("LIVES" if foresee_fate(cur_state) else "DIES")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top