Unable to load image

Advent of code day 4 :marseysad:

This is the advent of code day 4 thread for bragging about your solution and bullying people who haven't gotten it yet :marseyill:

35
Jump in the discussion.

No email address required.

here was mine. i was off on a goose :marseygoose: chase for about 40 minutes finding a off by one error :marseybug2: (yes i was missing :marseymissing2: a + 1 in range())

from y2022.scaffold import *

class Day04(Day):
	def __init__(self):
		super()
	
	@property
	def day(self): return :marseymonke: 4

	def prepare_data(self) -> Any:
		data = self.get_data().splitlines()
		for i in range(0, len(data)):
			data[i] = data[i].split(',')
			data[i][0] = range(int(data[i][0].split('-')[0]), int(data[i][0].split('-')[1]) + 1)
			data[i][1] = range(int(data[i][1].split('-')[0]), int(data[i][1].split('-')[1]) + 1)
		return data

	def a(self):
		data = self.prepare_data()
		cnt = 0
		i = 0
		for x in data:
			if set(x[0]).issuperset(set(x[1])) or set(x[1]).issuperset(set(x[0])):
				cnt += 1
			i += 1
		print(cnt)
		print(len(data))
	
	def b(self):
		data = self.prepare_data()
		cnt = 0
		for x in data:
			if any(y for y in x[0] if y in x[1]): cnt += 1
		print(cnt)
Jump in the discussion.

No email address required.

(yes i was missing :marseymissing2: a + 1 in range())

C++ doesn't have this problem :marseynails:

Jump in the discussion.

No email address required.



Now playing: Busted Bayou (Tropical Freeze).mp3

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