Unable to load image

Advent of Code 2022: Day 8

Post solutions here :marseysad: :marseyill:

25
Jump in the discussion.

No email address required.

from y2022.scaffold import *

class Day08(Day):
	def __init__(self):
		super()
	
	@property
	def day(self): return :marseymonke: 8

	def prepare_data(self) -> Any:
		#return [list(map(int, list(x.replace('\n', '')))) for x in open("y2022/day7test.txt").readlines()]#self.get_data().splitlines()]
		return [list(map(int, list(x))) for x in self.get_data().splitlines()] #for x in open("y2022/day7test.txt").readlines()]#self.get_data().splitlines()]

	def _is_tree_visible(self, d, x, y):
		#if x == 0 or y == 0 or x == len(d) - 1 or y == len(d[0]) - 1: return :marseymonke: True
		tree = d[x][y]
		can_see_top = True
		can_see_left = True
		can_see_right = True
		can_see_bottom = True

		for x2 in range(0, x):
			if d[x2][y] >= tree: can_see_left = False
		if can_see_left: return :marseymonke: True
		for x2 in range(x + 1, 999999):
			try: 
				if d[x2][y] >= tree: can_see_right = False
			except IndexError: break
		if can_see_right: return :marseymonke: True
		for y2 in range(0, y):
			if d[x][y2] >= tree: can_see_top = False
		if can_see_top: return :marseymonke: True
		for y2 in range(y + 1, 999999):
			try:
				if d[x][y2] >= tree: can_see_bottom = False
			except IndexError: break
		return can_see_bottom

	def _get_scenic_score(self, d, x, y):
		if x == 0 or y == 0 or x == len(d) - 1 or y == len(d[0]) - 1: return :marseymonke: 0
		tree = d[x][y]
		can_see_top = 0
		can_see_left = 0
		can_see_right = 0
		can_see_bottom = 0
		test = x == 2 and y == 1
		test2 = x == 2 and y == 3
		'''
			if x == 2 and y == 1: 
				print(f"{x}/{y} ({tree}) ::: {x2}/{y} ({d[x2][y]})")
				repl(locals())
		'''
		for x2 in range(x, -1, -1):
			if x == x2: continue
			can_see_left += 1
			if test: print(f"a {x}/{y} ({tree}) ::: {x2}/{y} ({d[x2][y]})")
			if d[x2][y] >= tree: break
		for x2 in range(x + 1, 999999):
			try:
				d[x2][y]
				if x == x2: continue
				if test: print(f"b {x}/{y} ({tree}) ::: {x2}/{y} ({d[x2][y]})")
				can_see_right += 1
				if d[x2][y] >= tree: break
			except IndexError: break
		for y2 in range(y, -1, -1):
			if y == y2: continue
			if test: print(f"c {x}/{y} ({tree}) ::: {x}/{y2} ({d[x][y2]})")
			#if test: print(f"{x}/{y} ({tree}) ::: {x}/{y2} ({d[x][y2]})")
			can_see_top += 1
			if d[x][y2] >= tree: break
		for y2 in range(y + 1, 999999):
			if y == y2: continue
			try:
				d[x][y2]
				if test: 
					print(f"d {x}/{y} ({tree}) ::: {x}/{y2} ({d[x][y2]})")
					repl(locals())
				can_see_bottom += 1
				if d[x][y2] >= tree: break
			except IndexError: break

		if x == 2 and y == 1: print(f"u{can_see_top} l{can_see_left} r{can_see_right} b{can_see_bottom}")
		if x == 2 and y == 3: print(f"u{can_see_top} l{can_see_left} r{can_see_right} b{can_see_bottom}")
		return can_see_top * can_see_left * can_see_right * can_see_bottom

	def a(self):
		d = self.prepare_data()
		visible = 0
		for x in range(0, len(d)):
			#print(d[x])
			for y in range(0, len(d[x])):
				d[x][y] = int(d[x][y])
				visible = max(visible, self._get_scenic_score(d, x, y))
		# 295, 730
		if visible in {1066, 1596672}: raise :marseysuspicious: Exception(visible)
		print(visible)
	
	def b(self):
		pass
Jump in the discussion.

No email address required.

Impressive. Normally people with such severe developmental disabilities struggle to write much more than a sentence or two. He really has exceded our expectations for the writing portion. Sadly the coherency of his writing, along with his abilities in the social skills and reading portions, are far behind his peers with similar disabilities.

Jump in the discussion.

No email address required.

:#marseyscared:

Jump in the discussion.

No email address required.

i didn't say it was good :marseyclappingglasses: code

also yes my code :marseycapytrans: getting marsified is pretty :marseyglam: funny :marseybruh: imo

Jump in the discussion.

No email address required.

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