day 5, hurrah for deques
This commit is contained in:
		
							
								
								
									
										1
									
								
								.tool-versions
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.tool-versions
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
python 3.9.9
 | 
			
		||||
							
								
								
									
										22
									
								
								d05/part1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								d05/part1.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
import sys
 | 
			
		||||
from collections import deque
 | 
			
		||||
# init data structure
 | 
			
		||||
S = list()
 | 
			
		||||
for _ in range(9):
 | 
			
		||||
	S.append(deque())
 | 
			
		||||
# parse initial positions
 | 
			
		||||
for _ in range(8):
 | 
			
		||||
	line = next(sys.stdin)
 | 
			
		||||
	for j in range(9):
 | 
			
		||||
		c = line[4*j+1]
 | 
			
		||||
		if c != " ":
 | 
			
		||||
			S[j].append(c)
 | 
			
		||||
line = next(sys.stdin)
 | 
			
		||||
line = next(sys.stdin)
 | 
			
		||||
# process
 | 
			
		||||
while line := sys.stdin.readline():
 | 
			
		||||
	_, q, _, f, _, t = line.strip().split(" ")
 | 
			
		||||
	for _ in range(int(q)):
 | 
			
		||||
		S[int(t)-1].appendleft(S[int(f)-1].popleft())
 | 
			
		||||
# print final positions
 | 
			
		||||
print("".join(s.popleft() for s in S))
 | 
			
		||||
							
								
								
									
										25
									
								
								d05/part2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								d05/part2.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
import sys
 | 
			
		||||
from collections import deque
 | 
			
		||||
# init data structure
 | 
			
		||||
S = list()
 | 
			
		||||
for _ in range(9):
 | 
			
		||||
	S.append(deque())
 | 
			
		||||
# parse initial positions
 | 
			
		||||
for _ in range(8):
 | 
			
		||||
	line = next(sys.stdin)
 | 
			
		||||
	for j in range(9):
 | 
			
		||||
		c = line[4*j+1]
 | 
			
		||||
		if c != " ":
 | 
			
		||||
			S[j].append(c)
 | 
			
		||||
line = next(sys.stdin)
 | 
			
		||||
line = next(sys.stdin)
 | 
			
		||||
# process
 | 
			
		||||
while line := sys.stdin.readline():
 | 
			
		||||
	_, q, _, f, _, t = line.strip().split(" ")
 | 
			
		||||
	tmp = deque()
 | 
			
		||||
	for _ in range(int(q)):
 | 
			
		||||
		tmp.append(S[int(f)-1].popleft())
 | 
			
		||||
	for _ in range(int(q)):
 | 
			
		||||
		S[int(t)-1].appendleft(tmp.pop())
 | 
			
		||||
# print final positions
 | 
			
		||||
print("".join(s.popleft() for s in S))
 | 
			
		||||
		Reference in New Issue
	
	Block a user