135 lines
3.5 KiB
Python
135 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
card_order = ["A", "K", "Q", "T", "9", "8", "7", "6", "5", "4", "3", "2", "J"]
|
|
hand_order = ["Five", "Four", "Full", "Three", "TwoPair", "Pair", "HighCard"]
|
|
inp = []
|
|
|
|
|
|
def card_sort(e):
|
|
return [card_order.index(c) for c in e]
|
|
|
|
|
|
input_file = open("input", "r")
|
|
for line in input_file:
|
|
line = line.strip().split()
|
|
hand = []
|
|
for b in line[0]:
|
|
hand.append(b)
|
|
inp.append([hand, line[1]])
|
|
input_file.close()
|
|
|
|
# for i in inp:
|
|
# print(i)
|
|
|
|
|
|
def hand_type(s):
|
|
joker = s.count("J")
|
|
for card in card_order:
|
|
if s.count(card)+joker == 5:
|
|
return "Five", s
|
|
for card in card_order:
|
|
if s.count(card)+joker == 4 and card != "J":
|
|
return "Four", s
|
|
for card in card_order:
|
|
if s.count(card)+joker == 3 and card != "J":
|
|
for cc in card_order:
|
|
if cc != card and s.count(cc) == 2 and cc != "J":
|
|
return "Full", s
|
|
return "Three", s
|
|
for card in card_order:
|
|
if s.count(card)+joker == 2 and card != "J":
|
|
for cc in card_order:
|
|
if cc != card and s.count(cc) == 2 and cc != "J":
|
|
return "TwoPair", s
|
|
return "Pair", s
|
|
return "High", s
|
|
|
|
|
|
typed_inp = []
|
|
for i in inp:
|
|
ty = hand_type(i[0])
|
|
typed_inp.append([ty[0], ty[1], i[1]])
|
|
|
|
|
|
# for i in typed_inp:
|
|
# print(i)
|
|
|
|
high_cards = []
|
|
pair_cards = []
|
|
two_pair_cards = []
|
|
three_cards = []
|
|
full_cards = []
|
|
four_cards = []
|
|
five_cards = []
|
|
|
|
hand_dic = {}
|
|
|
|
for t in typed_inp:
|
|
hand = "".join(t[1])
|
|
hand_dic[hand] = int(t[2])
|
|
if t[0] == "High":
|
|
high_cards.append(hand)
|
|
elif t[0] == "Pair":
|
|
pair_cards.append(hand)
|
|
elif t[0] == "TwoPair":
|
|
two_pair_cards.append(hand)
|
|
elif t[0] == "Three":
|
|
three_cards.append(hand)
|
|
elif t[0] == "Full":
|
|
full_cards.append(hand)
|
|
elif t[0] == "Four":
|
|
four_cards.append(hand)
|
|
elif t[0] == "Five":
|
|
five_cards.append(hand)
|
|
else:
|
|
print("Da ging was schief", t)
|
|
|
|
five_cards.sort(key=card_sort, reverse=True)
|
|
four_cards.sort(key=card_sort, reverse=True)
|
|
full_cards.sort(key=card_sort, reverse=True)
|
|
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)
|
|
|
|
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()
|
|
print(f"Lösung: {solution}")
|