2023-12-07 23:24:17 +02:00
|
|
|
#!/usr/bin/env python3.12
|
|
|
|
|
|
|
|
|
|
from functools import cmp_to_key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HandClass:
|
|
|
|
|
def __init__(self, bid, cards):
|
|
|
|
|
self.bid = bid
|
|
|
|
|
self.cards = cards
|
|
|
|
|
self.cardnumbers = []
|
|
|
|
|
self.numbers = {}
|
|
|
|
|
x = [*cards]
|
|
|
|
|
for i in x:
|
|
|
|
|
number = self.cardnumber(i)
|
|
|
|
|
self.cardnumbers.append(number)
|
|
|
|
|
if number not in self.numbers:
|
|
|
|
|
self.numbers[number] = 1
|
|
|
|
|
else:
|
|
|
|
|
self.numbers[number] += 1
|
|
|
|
|
x.sort(key=self.cardnumber, reverse=True)
|
|
|
|
|
self.sorted = x
|
|
|
|
|
self.strength = self.handstrength()
|
|
|
|
|
|
|
|
|
|
def cardnumber(self, x: str):
|
|
|
|
|
if x.isdigit():
|
|
|
|
|
return int(x)
|
|
|
|
|
if x == "T":
|
|
|
|
|
return 10
|
|
|
|
|
if x == "J":
|
|
|
|
|
return 1
|
|
|
|
|
if x == "Q":
|
|
|
|
|
return 12
|
|
|
|
|
if x == "K":
|
|
|
|
|
return 13
|
|
|
|
|
if x == "A":
|
|
|
|
|
return 14
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def handstrength(self):
|
|
|
|
|
print(self.numbers.values())
|
2023-12-08 19:06:27 +02:00
|
|
|
|
|
|
|
|
if 1 in self.numbers:
|
|
|
|
|
numofj = self.numbers[1]
|
|
|
|
|
else:
|
|
|
|
|
numofj = 0
|
|
|
|
|
|
2023-12-07 23:24:17 +02:00
|
|
|
nc = sorted(list(self.numbers.values()))
|
2023-12-08 19:06:27 +02:00
|
|
|
self.nc1 = nc
|
|
|
|
|
if numofj > 0 and len(nc) > 1:
|
|
|
|
|
for i in range(0, len(nc)):
|
|
|
|
|
if nc[i] == numofj:
|
|
|
|
|
nc.pop(i)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
nc[-1] += numofj
|
|
|
|
|
self.nc2 = nc
|
|
|
|
|
|
|
|
|
|
if len(nc) == 1:
|
|
|
|
|
return 6
|
|
|
|
|
|
2023-12-07 23:24:17 +02:00
|
|
|
if len(nc) == 2 and nc[1] == 4:
|
|
|
|
|
return 5
|
|
|
|
|
if len(nc) == 2 and nc[1] == 3:
|
|
|
|
|
return 4
|
|
|
|
|
if len(nc) == 3 and nc[2] == 3:
|
|
|
|
|
return 3
|
|
|
|
|
if len(nc) == 3 and nc[2] == 2:
|
|
|
|
|
return 2
|
|
|
|
|
if len(nc) == 4:
|
|
|
|
|
return 1
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-12-08 19:06:27 +02:00
|
|
|
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}, str: {self.strength}, n1: {self.nc1}, n2 {self.nc2}"
|
2023-12-07 23:24:17 +02:00
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def compare(c1, c2):
|
|
|
|
|
if c1.strength > c2.strength:
|
|
|
|
|
return 1
|
|
|
|
|
if c1.strength < c2.strength:
|
|
|
|
|
return -1
|
|
|
|
|
if c1.strength == c2.strength:
|
|
|
|
|
for i in range(0, len(c1.cardnumbers)):
|
|
|
|
|
if c1.cardnumbers[i] > c2.cardnumbers[i]:
|
|
|
|
|
return 1
|
|
|
|
|
if c1.cardnumbers[i] < c2.cardnumbers[i]:
|
|
|
|
|
return -1
|
2023-12-08 19:06:27 +02:00
|
|
|
return 0
|
2023-12-07 23:24:17 +02:00
|
|
|
|
|
|
|
|
|
2023-12-08 19:06:27 +02:00
|
|
|
with open("data2.txt") as file:
|
2023-12-07 23:24:17 +02:00
|
|
|
lines = [line.rstrip() for line in file]
|
|
|
|
|
|
|
|
|
|
hands = []
|
|
|
|
|
for line in lines:
|
2023-12-08 19:06:27 +02:00
|
|
|
if line == '':
|
|
|
|
|
print("Tühi rida")
|
|
|
|
|
continue
|
|
|
|
|
print(line)
|
2023-12-07 23:24:17 +02:00
|
|
|
halves = line.split(" ")
|
|
|
|
|
hands.append(HandClass(halves[1], halves[0]))
|
|
|
|
|
print(hands[-1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h2 = sorted(hands, key=cmp_to_key(compare), reverse=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("sorditud")
|
|
|
|
|
total = 0
|
|
|
|
|
count = 0
|
|
|
|
|
for h in h2:
|
|
|
|
|
count += 1
|
|
|
|
|
total += count*int(h.bid)
|
|
|
|
|
print(h)
|
2023-12-08 19:06:27 +02:00
|
|
|
print(f"{h.bid} {count*int(h.bid)}")
|
2023-12-07 23:24:17 +02:00
|
|
|
|
|
|
|
|
print(total)
|