opti
This commit is contained in:
		@ -1,4 +1,4 @@
 | 
			
		||||
text: str = open("example.txt", "r").read()
 | 
			
		||||
text: str = open("input.txt", "r").read()
 | 
			
		||||
 | 
			
		||||
_value: int = 0
 | 
			
		||||
 | 
			
		||||
@ -7,13 +7,13 @@ lines = text.splitlines()
 | 
			
		||||
CARDS = "AKQJT98765432"
 | 
			
		||||
 | 
			
		||||
def get_same(string: str):
 | 
			
		||||
	sames = {"key": string}
 | 
			
		||||
	same = {"key": string}
 | 
			
		||||
	for card in CARDS:
 | 
			
		||||
		if string.count(card) != 0:
 | 
			
		||||
			bozo: list = sames.get(string.count(card), "")
 | 
			
		||||
			bozo: list = same.get(string.count(card), "")
 | 
			
		||||
			bozo += (card)
 | 
			
		||||
			sames.update({string.count(card): bozo})
 | 
			
		||||
	return sames
 | 
			
		||||
			same.update({string.count(card): bozo})
 | 
			
		||||
	return same
 | 
			
		||||
 | 
			
		||||
sames = []
 | 
			
		||||
for line in lines:
 | 
			
		||||
@ -46,7 +46,7 @@ def get_index(lst: [dict], key: str):
 | 
			
		||||
 | 
			
		||||
sort = [sames[0]]
 | 
			
		||||
for same in sames[1:]:
 | 
			
		||||
	places = []
 | 
			
		||||
	place = None
 | 
			
		||||
	opponents: [dict] = sort.copy()
 | 
			
		||||
	for card_index in range(5, 0, -1):
 | 
			
		||||
		new = []
 | 
			
		||||
@ -57,22 +57,18 @@ for same in sames[1:]:
 | 
			
		||||
			if (highest == 0):
 | 
			
		||||
				new.append(opponent)
 | 
			
		||||
			elif (highest == 1):
 | 
			
		||||
				places.append(get_index(sort, opponent.get("key")))
 | 
			
		||||
				index = get_index(sort, opponent.get("key"))
 | 
			
		||||
				place = index if place == None else min(place, index)
 | 
			
		||||
		opponents = new
 | 
			
		||||
		if (places != []):
 | 
			
		||||
		if (place != None):
 | 
			
		||||
			break
 | 
			
		||||
	if (places == []):
 | 
			
		||||
		places = [len(sort)]
 | 
			
		||||
	place = min(places)
 | 
			
		||||
	if (place == None):
 | 
			
		||||
		place = len(sort)
 | 
			
		||||
	sort.insert(place, same)
 | 
			
		||||
 | 
			
		||||
for i, line in enumerate(lines):
 | 
			
		||||
	key, value = line.split()
 | 
			
		||||
	for j, bozo in enumerate(sort):
 | 
			
		||||
		if (bozo.get("key", "") == key):
 | 
			
		||||
			rank: int = (len(lines) - j)
 | 
			
		||||
			_value += rank * bozo.get("value")
 | 
			
		||||
			print(f'{rank}, {bozo.get("key")} {bozo.get("value")}')
 | 
			
		||||
			break
 | 
			
		||||
for j, bozo in enumerate(sort):
 | 
			
		||||
	rank: int = (len(lines) - j)
 | 
			
		||||
	_value += rank * bozo.get("value")
 | 
			
		||||
	print(f'{rank}, {bozo.get("key")} {bozo.get("value")}')
 | 
			
		||||
 | 
			
		||||
print(_value)
 | 
			
		||||
		Reference in New Issue
	
	Block a user