Skip to content

Instantly share code, notes, and snippets.

@turanegaku
Created February 28, 2017 11:51
Show Gist options
  • Select an option

  • Save turanegaku/9fdcf678fe3e0be48f6abd80cfc37bf6 to your computer and use it in GitHub Desktop.

Select an option

Save turanegaku/9fdcf678fe3e0be48f6abd80cfc37bf6 to your computer and use it in GitHub Desktop.
import sys
if len(sys.argv) < 2:
print('Usage:\n$ python Lights.py 6575')
sys.exit(0)
answer = int(sys.argv[1])
print(answer)
dp = [-1] * 10000
a = []
dp[0] = 0
a.append(0)
while a:
b = a[0]
a = a[1:]
b1 = (b + 7) % 10000
b2 = (b * 10) % 10000
if dp[b1] == -1:
a.append(b1)
dp[b1] = b
if dp[b2] == -1:
a.append(b2)
dp[b2] = b
if b1 == answer or b2 == answer:
break
print('===========')
i = answer
while True:
print(i)
i = dp[i]
if i == 0:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment