Created
December 2, 2016 10:02
-
-
Save kviktor/eebf4ce0d1e6969ea652d9d68f4550d7 to your computer and use it in GitHub Desktop.
advent 2016 day 2
This file contains 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
# flake8: noqa | |
instructions = ["ULL", "RRDDD", "LURDL", "UUUUD", ] | |
idx = 5 | |
commands = { | |
"U": -3, | |
"R": 1, | |
"L": -1, | |
"D": 3, | |
} | |
def can_step(idx, step): | |
return not ( | |
(idx in [3, 6, 9] and step == 1) or | |
(idx in [1, 4, 7] and step == -1) or | |
(idx in [1, 2, 3] and step == -3) or | |
(idx in [7, 8, 9] and step == 3) | |
) | |
for instruction in instructions: | |
for i in instruction: | |
step = commands.get(i) | |
if can_step(idx, step): | |
idx += step | |
print(idx, end="") |
This file contains 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
# flake8: noqa | |
instructions = ["ULL", "RRDDD", "LURDL", "UUUUD",] | |
idx = 11 | |
commands = { | |
"U": -5, | |
"R": 1, | |
"L": -1, | |
"D": 5, | |
} | |
translate = { | |
3: 1, 7:2, 8:3, 9:4, 11:5, 12:6, 13:7, 14:8, 15:9, | |
17: 10, 18: 11, 19: 12, 23: 13 | |
} | |
for instruction in instructions: | |
for i in instruction: | |
step = commands.get(i) | |
if translate.get(idx + step): | |
idx += step | |
print("%x" % translate.get(idx), end="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment