Skip to content

Instantly share code, notes, and snippets.

@shaunlgs
Created August 11, 2016 17:51
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 shaunlgs/1b4f1f1660ee718348596a5be927ac9d to your computer and use it in GitHub Desktop.
Save shaunlgs/1b4f1f1660ee718348596a5be927ac9d to your computer and use it in GitHub Desktop.
n = int(input())
raw = input().split(" ")
decisions = []
# decide first move
for i in range(1):
# gym no, contest no
if raw[i] == "0":
decisions.append("Rest")
# gym no, contest yes
elif raw[i] == "1":
decisions.append("Contest")
# gym yes, contest no
elif raw[i] == "2":
decisions.append("Gym")
# gym yes, contest yes
elif raw[i] == "3":
index = i
while True:
# still does not meet any no in the end
# example: yes yes, yes yes, yes yes, yes yes
if index == n - 1:
# choose any
decisions.append("Gym")
break
# gym no, contest no
if raw[index + 1] == "0":
# choose any
decisions.append("Gym")
break
# gym no, contest yes
elif raw[index + 1] == "1":
decisions.append("Gym")
break
# gym yes, contest no
elif raw[index + 1] == "2":
decisions.append("Contest")
break
# gym yes, contest yes
elif raw[index + 1] == "3":
index += 1
for i in range(1, n):
# gym no, contest no
if raw[i] == "0":
decisions.append("Rest")
# gym no, contest yes
elif raw[i] == "1":
if decisions[i - 1] == "Rest":
decisions.append("Contest")
elif decisions[i - 1] == "Gym":
decisions.append("Contest")
elif decisions[i - 1] == "Contest":
decisions.append("Rest")
# gym yes, contest no
elif raw[i] == "2":
if decisions[i - 1] == "Rest":
decisions.append("Gym")
elif decisions[i - 1] == "Gym":
decisions.append("Rest")
elif decisions[i - 1] == "Contest":
decisions.append("Gym")
# gym yes, contest yes
elif raw[i] == "3":
if decisions[i - 1] == "Rest":
index = i
while True:
# still does not meet any no in the end
# example: yes yes, yes yes, yes yes, yes yes
if index == n - 1:
# choose any
decisions.append("Gym")
break
# gym no, contest no
if raw[index + 1] == "0":
# choose any
decisions.append("Gym")
break
# gym no, contest yes
elif raw[index + 1] == "1":
decisions.append("Gym")
break
# gym yes, contest no
elif raw[index + 1] == "2":
decisions.append("Contest")
break
# gym yes, contest yes
elif raw[index + 1] == "3":
index += 1
elif decisions[i - 1] == "Gym":
decisions.append("Contest")
elif decisions[i - 1] == "Contest":
decisions.append("Gym")
restCount = 0
for i in range(n):
if decisions[i] == "Rest":
restCount += 1
print(restCount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment