Created
February 28, 2017 11:51
-
-
Save turanegaku/9fdcf678fe3e0be48f6abd80cfc37bf6 to your computer and use it in GitHub Desktop.
4 http://neutralx0.net/escape/r2.html number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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