Advent of Code Solutions Thread: Day Two

Only shitty solutions allowed

38
Jump in the discussion.

No email address required.

from y2022.scaffold import *

class Day02(Day):
	ROCK = ['a', 'x']
	PAPER = ['b', 'y']
	SCISSORS = ['c', 'z']
	def __init__(self):
		super()
	
	@property
	def day(self): return :marseymonke: 2

	def a(self):
		data = self.get_data()
		data = split_2d(data, '\n', ' ')
		t = 0
		for round in data:
			#print(round)
			#input()
			outcome = 0
			extra = 0
			if len(round) == 1: continue
			round[0] = round[0].lower()
			round[1] = round[1].lower()
			if round[1] == 'x': extra = 1
			if round[1] == 'y': extra = 2
			if round[1] == 'z': extra = 3
			if self.beats(round[1].lower(), round[0].lower()):
				outcome = 6
			elif (round[0] in self.ROCK and round[1] in self.ROCK) or (round[0] in self.PAPER and round[1] in self.PAPER) or (round[0] in self.SCISSORS and round[1] in self.SCISSORS):
				outcome = 3
			else:
				outcome = 0
			t += outcome + extra
		print(t)

	def calc_score(self, data):
		t = 0
		for round in data:
			#print(round)
			#input()
			outcome = 0
			extra = 0
			if len(round) == 1: continue
			round[0] = round[0].lower()
			round[1] = round[1].lower()
			if round[1] == 'x': extra = 1
			if round[1] == 'y': extra = 2
			if round[1] == 'z': extra = 3
			if self.beats(round[1].lower(), round[0].lower()):
				outcome = 6
			elif (round[0] in self.ROCK and round[1] in self.ROCK) or (round[0] in self.PAPER and round[1] in self.PAPER) or (round[0] in self.SCISSORS and round[1] in self.SCISSORS):
				outcome = 3
			else:
				outcome = 0
			t += outcome + extra
		return t

	def calc_score2(self, data):
		t = 0
		for round in data:
			#input()
			if len(round) == 1: continue
			outcome = -1
			extra = 0
			round[0] = round[0].lower()
			round[1] = round[1].lower()
			if round[1] == 'x': outcome = 0
			if round[1] == 'y': outcome = 3
			if round[1] == 'z': outcome = 6

			# x = lose y = draw z = win
			# hewekrpwkowfdmlkdffdf
			
			# this is evil
			y = ""
			x = round[0]
			if round[1] == 'z':
				x = round[0]
				round[0] = self.loses2(round[0])
				#print(f'win from {self.name(x)} to {self.name(round[0])}')
				#input()
				y = "win"
			if round[1] == 'x': 
				x = round[0]
				round[0] = self.beats2(round[0])
				#print(f'loss from {self.name(x)} to {self.name(round[0])}')
				#input()
				y = "loss"
			if round[1] == 'y':
				y = "tie"
			
			if round[0] == 'a': extra = 1
			if round[0] == 'b': extra = 2
			if round[0] == 'c': extra = 3
			

			if extra == 0: raise :marseysuspicious: Exception()
			if outcome == -1: raise :marseysuspicious: Exception()
			#print(round[0])
			t += outcome + extra
			if round[1] == 'y': continue
			print(f"{y} | me: {self.name(round[0])} opponent: {self.name(x)} (outcome {outcome}, extra {extra}, add {outcome + extra}, ttl {t})")
		return t
	
	@classmethod
	def beats(cls, x,y):
		if x.lower() in cls.ROCK: return :marseymonke: y in cls.SCISSORS
		if x.lower() in cls.PAPER: return :marseymonke: y in cls.ROCK
		if x.lower() in cls.SCISSORS: return :marseymonke: y in cls.PAPER
		raise Exception()

	@classmethod
	def beats2(cls, x):
		if x.lower() in cls.ROCK: return :marseymonke: cls.SCISSORS[0]
		if x.lower() in cls.PAPER: return :marseymonke: cls.ROCK[0]
		if x.lower() in cls.SCISSORS: return :marseymonke: cls.PAPER[0]
		raise Exception()

	@classmethod
	def loses2(cls, x):
		if x.lower() in cls.ROCK: return :marseymonke: cls.PAPER[0]
		if x.lower() in cls.PAPER: return :marseymonke: cls.SCISSORS[0]
		if x.lower() in cls.SCISSORS: return :marseymonke: cls.ROCK[0]
		raise Exception()

	@classmethod
	def name(cls, x):
		if x == 'a': return :marseymonke: 'rock'
		if x == 'b': return :marseymonke: 'paper'
		if x == 'c': return :marseymonke: 'scissor'
		raise Exception()

	def b(self):
		data = self.get_data()
		data = split_2d(data, '\n', ' ')
		print(self.calc_score2(data))
		pass
Jump in the discussion.

No email address required.

That was a mistake. You're about to find out the hard way why.

Jump in the discussion.

No email address required.

yes the calc score function is completely unused i thought i might need it for part 2

Jump in the discussion.

No email address required.

tfw you get longpostbot to comment on your code :marseytabletired2:

Jump in the discussion.

No email address required.

:marseyitsover:

Jump in the discussion.

No email address required.

:#marseypainter:

Jump in the discussion.

No email address required.

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