part1 with min value add to index 0 omegacringe

This commit is contained in:
starnakin 2023-12-07 09:43:34 +01:00
parent 677f8350a0
commit b6f3782b51
2 changed files with 83 additions and 0 deletions

7
2023/day07/example.txt Normal file
View File

@ -0,0 +1,7 @@
32T3K 765
T55J5 684
KTJJT 220
QQQJA 483
77777 1
KK677 28
12345 2

76
2023/day07/src/part1.py Normal file
View File

@ -0,0 +1,76 @@
text: str = open("example.txt", "r").read()
_value: int = 0
lines = text.splitlines()
CARDS = "AKQJT98765432"
def get_same(string: str):
sames = {"original": string}
for card in CARDS:
if string.count(card) != 0:
bozo: list = sames.get(string.count(card), [])
bozo.append(card)
sames.update({string.count(card): bozo})
return sames
sames = []
for line in lines:
bozo: [str] = line.split()
same = get_same(bozo[0])
sames.append(same)
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
for k in range(min(len(cards2), len(cards1))):
if (cards2[k] == cards1[k]):
continue
if (CARDS.index(cards1[k]) > CARDS.index(cards2[k])):
return 2
else:
return 1
return 0
sort = [sames[0]]
for same in sames[1:]:
place = None
for i in range(5, 0, -1):
cards = same.get(i)
if (cards == None):
continue
for j, bozo in enumerate(sort):
_cards = bozo.get(i)
if _cards is None:
continue
highest = get_highest(_cards, cards, i)
if (highest == 0 or highest == 1):
continue
else:
place = j
break
if (place is None):
place = 0
break
if (place is not None):
break
if (place is None):
print(same, i)
place = 0
sort.insert(place, same)
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) * int(value)
print( (len(lines) - j), bozo.get("original"))
break
print(_value)