korras
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3.12
|
||||
|
||||
from functools import cmp_to_key
|
||||
|
||||
|
||||
class HandClass:
|
||||
@@ -9,14 +11,15 @@ class HandClass:
|
||||
self.numbers = {}
|
||||
x = [*cards]
|
||||
for i in x:
|
||||
self.cardnumbers.append(self.cardnumber(i))
|
||||
if i not in self.numbers:
|
||||
self.numbers[self.cardnumber(i)] = 1
|
||||
number = self.cardnumber(i)
|
||||
self.cardnumbers.append(number)
|
||||
if number not in self.numbers:
|
||||
self.numbers[number] = 1
|
||||
else:
|
||||
self.numbers[self.cardnumber(i)] += 1
|
||||
self.numbers[number] += 1
|
||||
x.sort(key=self.cardnumber, reverse=True)
|
||||
self.sorted = x
|
||||
self.handstrength()
|
||||
self.strength = self.handstrength()
|
||||
|
||||
def cardnumber(self, x: str):
|
||||
if x.isdigit():
|
||||
@@ -36,16 +39,48 @@ class HandClass:
|
||||
def handstrength(self):
|
||||
print(self.numbers.values())
|
||||
if len(set(self.cardnumbers)) == 1:
|
||||
return 6
|
||||
nc = sorted(list(self.numbers.values()))
|
||||
if len(nc) == 2 and nc[1] == 4:
|
||||
return 5
|
||||
if len(self.numbers)==2:
|
||||
print("2")
|
||||
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):
|
||||
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}"
|
||||
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}, str: {self.strength}"
|
||||
|
||||
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 == 0 and c2.strength == 0:
|
||||
# for i in range(0, len(c1.sorted)):
|
||||
# if c1.sorted[i] > c2.sorted[i]:
|
||||
# return 1
|
||||
# if c1.sorted[i] < c2.sorted[i]:
|
||||
# return -1
|
||||
# return 0
|
||||
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
|
||||
return 0
|
||||
|
||||
|
||||
with open("data.txt") as file:
|
||||
lines = [line.rstrip() for line in file]
|
||||
|
||||
@@ -54,3 +89,17 @@ for line in lines:
|
||||
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)
|
||||
|
||||
print(total)
|
||||
|
||||
Reference in New Issue
Block a user