opti
This commit is contained in:
parent
c9a3d978d8
commit
f8a88e4220
@ -1,4 +1,4 @@
|
||||
text: str = open("input.txt", "r").read()
|
||||
text: str = open("example.txt", "r").read()
|
||||
|
||||
_value: int = 0
|
||||
|
||||
@ -7,7 +7,7 @@ lines = text.splitlines()
|
||||
CARDS = "AKQJT98765432"
|
||||
|
||||
def get_same(string: str):
|
||||
sames = {"original": string}
|
||||
sames = {"key": string}
|
||||
for card in CARDS:
|
||||
if string.count(card) != 0:
|
||||
bozo: list = sames.get(string.count(card), "")
|
||||
@ -26,22 +26,22 @@ for line in lines:
|
||||
def get_highest(cards1, cards2, i):
|
||||
if (cards1 == cards2):
|
||||
return 0
|
||||
if (i != 1 and len(cards2) > len(cards1)):
|
||||
return 2
|
||||
if (i != 1 and len(cards1) > len(cards2)):
|
||||
return 1
|
||||
if (i != 1):
|
||||
l1 = len(cards1)
|
||||
l2 = len(cards2)
|
||||
if (l1 > l2):
|
||||
return 1
|
||||
if (l2 > l1):
|
||||
return 2
|
||||
for char1, char2 in zip(cards1, cards2):
|
||||
if (char2 == char1):
|
||||
continue
|
||||
if (CARDS.index(char1) > CARDS.index(char2)):
|
||||
return 2
|
||||
else:
|
||||
return 1
|
||||
return 1 + (CARDS.index(char1) > CARDS.index(char2))
|
||||
return 0
|
||||
|
||||
def get_index(lst: [dict], original: str):
|
||||
def get_index(lst: [dict], key: str):
|
||||
for i, hand in enumerate(lst):
|
||||
if (hand.get("original") == original):
|
||||
if (hand.get("key") == key):
|
||||
return i
|
||||
|
||||
sort = [sames[0]]
|
||||
@ -57,7 +57,8 @@ for same in sames[1:]:
|
||||
if (highest == 0):
|
||||
new.append(opponent)
|
||||
elif (highest == 1):
|
||||
places.append(get_index(sort, opponent.get("original")))
|
||||
places.append(get_index(sort, opponent.get("key")))
|
||||
else:
|
||||
opponents = new
|
||||
if (places != []):
|
||||
break
|
||||
@ -69,9 +70,10 @@ for same in sames[1:]:
|
||||
for i, line in enumerate(lines):
|
||||
key, value = line.split()
|
||||
for j, bozo in enumerate(sort):
|
||||
if (bozo.get("original", "") == key):
|
||||
_value += (len(lines) - j) * bozo.get("value")
|
||||
print(f'{(len(lines) - j)}, {bozo.get("value")}')
|
||||
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
|
||||
|
||||
print(_value)
|
Loading…
Reference in New Issue
Block a user