Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #AoC 2016 Puzzle 2a
- input_file_object = open("aoc16_input_2a.txt")
- input_as_string = input_file_object.read()
- input_file_object.close()
- keypad = ((1,2,3),(4,5,6),(7,8,9))
- start_y = 1
- start_x = 1
- keycode = []
- input_by_line = input_as_string.split("\n")
- for sequence in input_by_line:
- print(start_x)
- print(start_y)
- for char in sequence:
- if char == 'U':
- if start_y > 0:
- start_y -= 1
- elif char == 'D':
- if start_y < 2:
- start_y += 1
- elif char == 'L':
- if start_x > 0:
- start_x -= 1
- elif char == 'R':
- if start_x < 2:
- start_x += 1
- keycode.append(keypad[start_y][start_x])
- print(keycode)
- #Time for 1b
- keypad = (('','','1','',''),('','2','3','4',''),('5','6','7','8','9'),('','A','B','C',''),('','','D','',''))
- start_y = 2
- start_x = 0
- keycode = []
- for sequence in input_by_line:
- print(start_x)
- print(start_y)
- for char in sequence:
- if char == 'U':
- if start_y > 0 and keypad[start_y - 1][start_x] != '':
- start_y -= 1
- elif char == 'D':
- if start_y < 4 and keypad[start_y + 1][start_x] != '':
- start_y += 1
- elif char == 'L':
- if start_x > 0 and keypad[start_y][start_x -1] != '':
- start_x -= 1
- elif char == 'R':
- if start_x < 4 and keypad[start_y][start_x +1] != '':
- start_x += 1
- keycode.append(keypad[start_y][start_x])
- print(keycode)
Add Comment
Please, Sign In to add comment