Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Day5 Python3
- Parsing
- import re
- f=open('input.txt')
- pack,moves=f.read().split("\n\n")
- pack=pack.split("\n")
- x=list(map(int,re.findall("[0-9]+",moves)))
- moves=[x[i:i+3] for i in range(0,len(x),3) ]
- ind=list(m.start(0) for m in re.finditer("[0-9]+",pack[len(pack)-1]))
- #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è
- crates=[]
- for i in ind:
- col=[]
- for j in range(len(pack)-2,-1,-1):
- if pack[j][i]!=" ":
- col.append(pack[j][i])
- crates.append(col)
- Part 1
- for x in moves:
- for i in range(x[0]):
- crates[x[2]-1].append(crates[x[1]-1].pop())
- print(''.join(crates[i][len(crates[i])-1] for i in range(len(crates))))
- Part 2
- for x in moves:
- rem=[]
- for i in range(x[0]): rem.append(crates[x[1]-1].pop())
- for i in range(x[0]): crates[x[2] - 1].append(rem[-i-1])
- print(''.join(crates[i][len(crates[i])-1] for i in range(len(crates))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement