day 20 aoc: the cupid shuffle

https://youtube.com/watch?v=h24_zoqu4_Q

to the right to the right to the right

to the left to the left to the left

post your aoc solutions for day 20 or smth, all checks notes 5+ of you

42
Jump in the discussion.

No email address required.

my solution (unedited, might edit later :marseywave2: idk)


from collections import deque

import copy

from y2022.scaffold import *

class Day20(Day):
	def __init__(self, test_file:bool=False):
		super().__init__(test_file)
	
	@property
	def day(self): return :marseymonke: 20

	def prepare_data(self):
		data = list((n, i) for n, i in enumerate(list(map(int, self.get_data().splitlines()))))
		return data

	def a(self):
		data_no_modify = self.prepare_data()
		data_modify = deque(copy.deepcopy(data_no_modify))
		data_no_modify_q = deque(copy.deepcopy(data_no_modify))
		for idx, value in data_no_modify_q:
			#print(data_modify)
			data_modify.rotate(-data_modify.index((idx, value)))
			idx2, value2 = data_modify.popleft()
			data_modify.rotate(-value2)
			data_modify.appendleft((idx2, value2))

		data_modify2 = list(i for _, i in data_modify)

		x = data_modify2[(1000 + data_modify2.index(0)) % len(data_modify2)]
		y = data_modify2[(2000 + data_modify2.index(0)) % len(data_modify2)]
		z = data_modify2[(3000 + data_modify2.index(0)) % len(data_modify2)]
		print(f'{x} {y} {z} - answer: {x + y + z}')
	
	def b(self):
		data = self.prepare_data()
		KEY = 811589153
		data_no_modify = deque(map(lambda n:(n[0], n[1] * KEY), self.prepare_data()))
		data_modify = deque(copy.deepcopy(data_no_modify))
		data_no_modify_q = deque(copy.deepcopy(data_no_modify))
		for _ in range(10):
			for idx, value in data_no_modify_q:
				data_modify.rotate(-data_modify.index((idx, value)))
				idx2, value2 = data_modify.popleft()
				data_modify.rotate(-value2)
				data_modify.appendleft((idx2, value2))

		data_modify2 = list(i for _, i in data_modify)

		x = data_modify2[(1000 + data_modify2.index(0)) % len(data_modify2)]
		y = data_modify2[(2000 + data_modify2.index(0)) % len(data_modify2)]
		z = data_modify2[(3000 + data_modify2.index(0)) % len(data_modify2)]
		print(f'{x} {y} {z} - answer: {x + y + z}')
Jump in the discussion.

No email address required.

clean it up jannie!

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.