07-1 fertig

This commit is contained in:
2023-12-07 19:49:33 +01:00
parent 51fa3d4c41
commit df9b6d07c8
4 changed files with 151 additions and 9 deletions

View File

@@ -33,17 +33,19 @@ def hand_type(s):
for c in card_order:
if s.count(c) == 4:
return "Four", s
elif ss.count(c) == 3 and (((ss[0] == ss[1] or ss[0] == ss[4]) and ss[0] != c) or (ss[3] == s[4] and ss[3] != c)):
return "Full", s
elif ss.count(c) == 3:
for cc in card_order:
if cc != c and ss.count(cc) == 2:
return "Full", s
return "Three", s
elif ss.count(c) == 2:
for cc in card_order:
if cc != c and ss.count(cc) == 2:
return "TwoPair", s
elif cc != c and ss.count(cc) == 3:
return "Full", s
return "Pair", s
else:
return "High", s
return "High", s
typed_inp = []
@@ -52,8 +54,8 @@ for i in inp:
typed_inp.append([ty[0], ty[1], i[1]])
for i in typed_inp:
print(i)
# for i in typed_inp:
# print(i)
high_cards = []
pair_cards = []
@@ -92,31 +94,44 @@ three_cards.sort(key=card_sort, reverse=True)
two_pair_cards.sort(key=card_sort, reverse=True)
pair_cards.sort(key=card_sort, reverse=True)
high_cards.sort(key=card_sort, reverse=True)
#for c in high_cards:
# print(c)
solution = 0
i = 0
print("High -----------------------------------------")
for card in high_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print("Pair -----------------------------------------")
for card in pair_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print("Two Pair -----------------------------------------")
for card in two_pair_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print("ThreeCards -----------------------------------------")
for card in three_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print("FullHouse -----------------------------------------")
for card in full_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print("FourCards -----------------------------------------")
for card in four_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print("FiveCards -----------------------------------------")
for card in five_cards:
i += 1
solution += i*hand_dic[card]
print(i, card, hand_dic[card])
print(solution, i)
print()
print(f"Lösung: {solution}")

107
07/AOCDay7-Eric.py Normal file
View File

@@ -0,0 +1,107 @@
file = open("input", "r")
bids = []
hands = []
rating = {"A": 13, "K": 12, "Q": 11, "J": 10, "T": 9, "9": 8, "8": 7, "7": 6, "6": 5, "5": 4, "4": 3, "3": 2, "2": 1}
for line in file:
count_dict = {}
line = line.strip().split()
bids.append("")
bids.append(line[1].strip())
hands.append(line[0])
for char in line[0]:
if count_dict.get(char):
count_dict[char] += 1
else:
count_dict[char] = 1
hands.append(count_dict)
five_of = []
four_of = []
three_of = []
two_pair = []
one_pair = []
high_card = []
full_house = []
for i in range(len(hands)):
hand = hands[i]
if type(hand) is dict:
if len(hand) == 1:
five_of.append(hands[i - 1])
five_of.append(hand)
five_of.append(bids[i])
continue
elif len(hand) == 4:
one_pair.append(hands[i - 1])
one_pair.append(hand)
one_pair.append(bids[i])
continue
elif len(hand) == 5:
high_card.append(hands[i - 1])
high_card.append(hand)
high_card.append(bids[i])
continue
for j in hand:
if (len(hand) == 2) and (hand[j] == 2 or hand[j] == 3):
full_house.append(hands[i - 1])
full_house.append(hand)
full_house.append(bids[i])
break
elif hand[j] == 4:
four_of.append(hands[i - 1])
four_of.append(hand)
four_of.append(bids[i])
break
elif len(hand) == 3 and hand[j] == 3:
three_of.append(hands[i - 1])
three_of.append(hand)
three_of.append(bids[i])
break
elif len(hand) == 3 and hand[j] == 2:
two_pair.append(hands[i - 1])
two_pair.append(hand)
two_pair.append(bids[i])
break
all_hands = [five_of, four_of, full_house, three_of, two_pair, one_pair, high_card]
specific_rate = len(bids) // 2
blaetter = []
hand_ratings = []
order = ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2", "1"]
my_list = ["KTJJT", "KK677"]
def custom_sort(s):
return [order.index(c) for c in s]
for hand in all_hands:
for i in range(1, len(hand)):
single_hand = hand[i]
val = 0
if type(single_hand) is dict:
if len(hand) > 3:
blaetter = []
for j in range(0, len(hand), 3):
blaetter.append(hand[j])
blaetter.sort(key=custom_sort)
else:
hand_ratings.append(specific_rate)
specific_rate -= 1
if i + 1 < len(hand):
hand_ratings.append(hand[i + 1])
continue
for i in range(len(blaetter)):
idx = hand.index(blaetter[i]) + 2
hand_ratings.append(specific_rate)
hand_ratings.append(hand[idx])
specific_rate -= 1
blaetter = []
werte = []
result = 0
for i in range(0, len(hand_ratings), 2):
print(hand_ratings[i], hand_ratings[i + 1])
result += int(hand_ratings[i]) * int(hand_ratings[i + 1])
print(result)

View File

@@ -3,3 +3,4 @@ T55J5 684
KK677 28
KTJJT 220
QQQJA 483
A222A 390

19
07/input-sr Normal file
View File

@@ -0,0 +1,19 @@
2345A 1
Q2KJJ 13
Q2Q2Q 19
T3T3J 17
T3Q33 11
2345J 3
J345A 2
32T3K 5
T55J5 29
KK677 7
KTJJT 34
QQQJA 31
JJJJJ 37
JAAAA 43
AAAAJ 59
AAAAA 61
2AAAA 23
2JJJJ 53
JJJJ2 41