Advertisement
Guest User

Untitled

a guest
Dec 8th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1.  
  2. FILE = 'stocks.txt'
  3.  
  4. with open(FILE, 'r') as input_file:
  5.     temporary_stokcs = input_file.readlines()
  6.     temporary_movement = temporary_stokcs[10:]
  7.     movements = []
  8.     for instruction in temporary_movement:
  9.         one_instruction = []
  10.         instruction = instruction.split(" ")
  11.         one_instruction.append(int(instruction[1]))
  12.         one_instruction.append(int(instruction[3]))
  13.         one_instruction.append(int(instruction[5].rstrip('\n')))
  14.         movements.append(one_instruction)
  15.  
  16. stocks = {
  17.     '1': ['Z','P','M','H','R'],
  18.     '2': ['P','C','J','B'],
  19.     '3': ['S','N','H','G','L','C','D'],
  20.     '4': ['F','T','M','D','Q','S','R','L'],
  21.     '5': ['F','S','P','Q','B','T','Z','M'],
  22.     '6': ['T','F','S','Z','B','G'],
  23.     '7': ['N','R','V'],
  24.     '8': ['P','G','L','T','D','V','C','M'],
  25.     '9': ['W','Q','N','J','F','M','L']
  26. }
  27. '''
  28. # test stocks input
  29. stocks = {
  30.    '1': ['Z','N'],
  31.    '2': ['M','C','D'],
  32.    '3': ['P']
  33. }
  34. '''
  35. '''
  36. # part I
  37. for instruction in movements:
  38.    #print(instruction)
  39.    for _ in range(instruction[0]):
  40.        element = stocks.get(f"{instruction[1]}").pop()
  41.        stocks.get(f"{instruction[2]}").append(element)
  42. '''
  43.  
  44.    
  45. for instruction in movements:
  46.     cut = int(instruction[0])
  47.     cutted_list = stocks.get(f"{instruction[1]}")[-cut:]
  48.     rest_list = [element for element in stocks.get(f"{instruction[1]}") if element not in cutted_list]
  49.     stocks[f"{instruction[1]}"] = rest_list
  50.     #print(f"before: {stocks[f'{instruction[2]}']}")
  51.     stocks[f"{instruction[2]}"].extend(cutted_list)
  52.     #print(f"after: {stocks[f'{instruction[2]}']}")
  53.  
  54.  
  55. for k,v in stocks.items():
  56.     print(k, v)
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement