Compare commits
No commits in common. "dfa1a49c7bbb951268dcc31eeda7dc2061f68f81" and "e13186dce03a282dd34ed9c070d6a46172cb914d" have entirely different histories.
dfa1a49c7b
...
e13186dce0
@ -1,4 +1,4 @@
|
|||||||
text: str = open("input.txt", "r").read()
|
text: str = open("example.txt", "r").read()
|
||||||
|
|
||||||
_value: int = 0
|
_value: int = 0
|
||||||
|
|
||||||
@ -7,13 +7,13 @@ lines = text.splitlines()
|
|||||||
CARDS = "AKQJT98765432"
|
CARDS = "AKQJT98765432"
|
||||||
|
|
||||||
def get_same(string: str):
|
def get_same(string: str):
|
||||||
same = {"key": string}
|
sames = {"key": string}
|
||||||
for card in CARDS:
|
for card in CARDS:
|
||||||
if string.count(card) != 0:
|
if string.count(card) != 0:
|
||||||
bozo: list = same.get(string.count(card), "")
|
bozo: list = sames.get(string.count(card), "")
|
||||||
bozo += (card)
|
bozo += (card)
|
||||||
same.update({string.count(card): bozo})
|
sames.update({string.count(card): bozo})
|
||||||
return same
|
return sames
|
||||||
|
|
||||||
sames = []
|
sames = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -22,7 +22,6 @@ for line in lines:
|
|||||||
same.update({"value": int(bozo[1])})
|
same.update({"value": int(bozo[1])})
|
||||||
sames.append(same)
|
sames.append(same)
|
||||||
|
|
||||||
#[print(same) for same in sames]
|
|
||||||
|
|
||||||
def get_highest(cards1, cards2, i):
|
def get_highest(cards1, cards2, i):
|
||||||
if (cards1 == cards2):
|
if (cards1 == cards2):
|
||||||
@ -47,7 +46,7 @@ def get_index(lst: [dict], key: str):
|
|||||||
|
|
||||||
sort = [sames[0]]
|
sort = [sames[0]]
|
||||||
for same in sames[1:]:
|
for same in sames[1:]:
|
||||||
place = None
|
places = []
|
||||||
opponents: [dict] = sort.copy()
|
opponents: [dict] = sort.copy()
|
||||||
for card_index in range(5, 0, -1):
|
for card_index in range(5, 0, -1):
|
||||||
new = []
|
new = []
|
||||||
@ -58,16 +57,22 @@ for same in sames[1:]:
|
|||||||
if (highest == 0):
|
if (highest == 0):
|
||||||
new.append(opponent)
|
new.append(opponent)
|
||||||
elif (highest == 1):
|
elif (highest == 1):
|
||||||
index = get_index(sort, opponent.get("key"))
|
places.append(get_index(sort, opponent.get("key")))
|
||||||
place = index if place == None else min(place, index)
|
|
||||||
opponents = new
|
opponents = new
|
||||||
if (place == None):
|
if (places != []):
|
||||||
place = len(sort)
|
break
|
||||||
|
if (places == []):
|
||||||
|
places = [len(sort)]
|
||||||
|
place = min(places)
|
||||||
sort.insert(place, same)
|
sort.insert(place, same)
|
||||||
|
|
||||||
for j, bozo in enumerate(sort):
|
for i, line in enumerate(lines):
|
||||||
rank: int = (len(lines) - j)
|
key, value = line.split()
|
||||||
_value += rank * bozo.get("value")
|
for j, bozo in enumerate(sort):
|
||||||
print(f'{rank} {bozo.get("key")} {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)
|
print(_value)
|
Loading…
Reference in New Issue
Block a user