Guest User

AoC_2016_2_Reibello

a guest
Dec 2nd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. #AoC 2016 Puzzle 2a
  2. input_file_object = open("aoc16_input_2a.txt")
  3. input_as_string = input_file_object.read()
  4. input_file_object.close()
  5.  
  6. keypad = ((1,2,3),(4,5,6),(7,8,9))
  7.  
  8. start_y = 1
  9. start_x = 1
  10.  
  11. keycode = []
  12.  
  13. input_by_line = input_as_string.split("\n")
  14.  
  15. for sequence in input_by_line:
  16.     print(start_x)
  17.     print(start_y)
  18.     for char in sequence:
  19.         if char == 'U':
  20.             if start_y > 0:
  21.                 start_y -= 1
  22.         elif char == 'D':
  23.             if start_y < 2:
  24.                 start_y += 1
  25.         elif char == 'L':
  26.             if start_x > 0:
  27.                 start_x -= 1
  28.         elif char == 'R':
  29.             if start_x < 2:
  30.                 start_x += 1
  31.     keycode.append(keypad[start_y][start_x])
  32.  
  33. print(keycode)
  34.  
  35. #Time for 1b
  36.  
  37. keypad = (('','','1','',''),('','2','3','4',''),('5','6','7','8','9'),('','A','B','C',''),('','','D','',''))
  38.  
  39. start_y = 2
  40. start_x = 0
  41.  
  42. keycode = []
  43.  
  44. for sequence in input_by_line:
  45.     print(start_x)
  46.     print(start_y)
  47.     for char in sequence:
  48.         if char == 'U':
  49.             if start_y > 0 and keypad[start_y - 1][start_x] != '':
  50.                 start_y -= 1
  51.         elif char == 'D':
  52.             if start_y < 4 and keypad[start_y + 1][start_x] != '':
  53.                 start_y += 1
  54.         elif char == 'L':
  55.             if start_x > 0 and keypad[start_y][start_x -1] != '':
  56.                 start_x -= 1
  57.         elif char == 'R':
  58.             if start_x < 4 and keypad[start_y][start_x +1] != '':
  59.                 start_x += 1
  60.     keycode.append(keypad[start_y][start_x])
  61. print(keycode)
Add Comment
Please, Sign In to add comment