poolik
This commit is contained in:
40
7/advent_1.py
Executable file
40
7/advent_1.py
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
class HandClass:
|
||||
def __init__(self, bid, cards):
|
||||
self.bid = bid
|
||||
self.cards = cards
|
||||
x = [*cards]
|
||||
x.sort(key=self.cardumber, reverse=True)
|
||||
self.sorted = x
|
||||
|
||||
def cardumber(self, x: str):
|
||||
if x.isdigit():
|
||||
return int(x)
|
||||
if x == "T":
|
||||
return 10
|
||||
if x == 'J':
|
||||
return 11
|
||||
if x == 'Q':
|
||||
return 12
|
||||
if x == 'K':
|
||||
return 13
|
||||
if x == 'A':
|
||||
return 14
|
||||
return 0
|
||||
|
||||
def __str__(self):
|
||||
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}"
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
|
||||
with open("data.txt") as file:
|
||||
lines = [line.rstrip() for line in file]
|
||||
|
||||
hands = []
|
||||
for line in lines:
|
||||
halves = line.split(' ')
|
||||
hands.append(HandClass(halves[1], halves[0]))
|
||||
print(hands[-1])
|
||||
Reference in New Issue
Block a user