Advertisement
icarussiano

Untitled

Dec 5th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. Day5 Python3
  2.  
  3. Parsing
  4. import re
  5. f=open('input.txt')
  6. pack,moves=f.read().split("\n\n")
  7. pack=pack.split("\n")
  8. x=list(map(int,re.findall("[0-9]+",moves)))
  9. moves=[x[i:i+3] for i in range(0,len(x),3) ]
  10. ind=list(m.start(0) for m in re.finditer("[0-9]+",pack[len(pack)-1]))
  11. #cerco gli indici dei numeri delle colonne che saranno gli stessi in cui ci sono le lettere nelle righe sovrasranti, in realtà basta range(1,len(riga),4) ma vabbè
  12. crates=[]
  13. for i in ind:
  14.     col=[]
  15.     for j in range(len(pack)-2,-1,-1):
  16.         if pack[j][i]!=" ":
  17.            col.append(pack[j][i])
  18.     crates.append(col)
  19.  
  20. Part 1
  21. for x in moves:
  22.     for i in range(x[0]):
  23.         crates[x[2]-1].append(crates[x[1]-1].pop())
  24. print(''.join(crates[i][len(crates[i])-1] for i in range(len(crates))))
  25.  
  26. Part 2
  27. for x in moves:
  28.     rem=[]
  29.     for i in range(x[0]): rem.append(crates[x[1]-1].pop())
  30.     for i in range(x[0]): crates[x[2] - 1].append(rem[-i-1])
  31. print(''.join(crates[i][len(crates[i])-1] for i in range(len(crates))))
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement