Решение на Тесте карти от Веселин Генадиев

Обратно към всички решения

Към профила на Веселин Генадиев

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

from itertools import product
SYMBOLS = ['K', 'Q', 'J', '10', '9', '8', '7', '6', '5', '4', '3', '2', 'A']
COLORS = ['black', 'red', 'red', 'black']
RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
def rank_symbol(rank):
return SYMBOLS[RANK_NAMES.index(rank)]
def suit_color(suit):
return COLORS[SUIT_NAMES.index(suit)]
class Rank:
def __init__(self):
self.rank
@property
def symbol(self):
return rank_symbol(self.rank)
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return self.rank
class Suit:
def __init__(self):
self.suit
@property
def color(self):
return suit_color(self.suit)
def __eq__(self, other):
return self.suit == other.suit
def __str__(self):
return self.suit
class Card:
def __init__(self, rank, suit):
self.__rank = rank()
self.__suit = suit()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return '{0} of {1}'.format(str(self.rank), str(self.suit))
def __repr__(self):
return '<Card {0}>'.format(str(self))
class CardCollection:
def __init__(self, collection=[]):
self.__collection = list(collection)
def draw(self, index):
return self.__collection.pop(index)
def draw_from_top(self):
return self.__collection.pop()
def draw_from_bottom(self):
return self.__collection.pop(0)
def top_card(self):
return self.__collection[-1]
def bottom_card(self):
return self.__collection[0]
def add(self, card):
self.__collection.append(card)
def index(self, card):
return self.__collection.index(card)
def __iter__(self):
return iter(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __len__(self):
return len(self.__collection)
def __str__(self):
return str(self.__collection)
def __repr__(self):
return repr(self.__collection)
RANKS = {rank_name: type(rank_name, (Rank,), dict(rank=rank_name))
for rank_name in RANK_NAMES}
SUITS = {suit_name: type(suit_name, (Suit,), dict(suit=suit_name))
for suit_name in SUIT_NAMES}
DECK = [Card(RANKS[rank], SUITS[suit]) for suit, rank
in product(SUIT_NAMES, RANK_NAMES)]
def StandardDeck():
return CardCollection(DECK)
def BeloteDeck():
excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)
def SixtySixDeck():
excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)

Лог от изпълнението

................
----------------------------------------------------------------------
Ran 16 tests in 0.020s

OK

История (5 версии и 1 коментар)

Веселин обнови решението на 25.03.2014 01:07 (преди около 10 години)

+from itertools import product
+
+
+class Rank:
+ def __init__(self):
+ self.symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.symbol
+
+
+class Suit:
+ def __init__(self):
+ self.color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.color
+
+
+RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
+ for symbol in RANK_NAMES}
+SUITS = {color: type(color, (Suit,), dict(color=color))
+ for color in SUIT_NAMES}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.properties = (rank(), suit())
+
+ @property
+ def rank(self):
+ return self.properties[0]
+
+ @property
+ def suit(self):
+ return self.properties[1]
+
+ def __eq__(self, other):
+ return str(self) == str(other)
+
+ def __str__(self):
+ return "{0} of {1}".format(self.properties[0], self.properties[1])
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ self.collection.index(card)
+
+ def __iter__(self):
+ return iter(self.collection)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandardDeck():
+ cards = [Card(RANKS[rank], SUITS[suit])
+ for rank, suit in product(RANK_NAMES, SUIT_NAMES)]
+ return CardCollection(cards)
+
+
+def BeloteDeck():
+ excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
+ cards = [Card(RANKS[rank], SUITS[suit])
+ for rank, suit in product(RANK_NAMES, SUIT_NAMES)
+ if rank not in excluded_ranks]
+ return CardCollection(cards)
+
+
+def SixtySixDeck():
+ excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
+ cards = [Card(RANKS[rank], SUITS[suit])
+ for rank, suit in product(RANK_NAMES, SUIT_NAMES)
+ if rank not in excluded_ranks]
+ return CardCollection(cards)

Веселин обнови решението на 25.03.2014 08:28 (преди около 10 години)

from itertools import product
class Rank:
def __init__(self):
self.symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.symbol
class Suit:
def __init__(self):
self.color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.color
RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
for symbol in RANK_NAMES}
SUITS = {color: type(color, (Suit,), dict(color=color))
for color in SUIT_NAMES}
class Card:
def __init__(self, rank, suit):
- self.properties = (rank(), suit())
+ self.__rank__ = rank()
+ self.__suit__ = suit()
@property
def rank(self):
- return self.properties[0]
+ return self.__rank__
@property
def suit(self):
- return self.properties[1]
+ return self.__suit__
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
- return "{0} of {1}".format(self.properties[0], self.properties[1])
+ return '{0} of {1}'.format(self.rank, self.suit)
+ def __repr__(self):
+ return '<Card {0}>'.format(str(self))
+
class CardCollection:
def __init__(self, collection=[]):
- self.collection = list(collection)
+ self.__collection__ = list(collection)
def draw(self, index):
- return self.collection.pop(index)
+ return self.__collection__.pop(index)
def draw_from_top(self):
- return self.collection.pop()
+ return self.__collection__.pop()
def draw_from_bottom(self):
- return self.collection.pop(0)
+ return self.__collection__.pop(0)
def top_card(self):
- return self.collection[-1]
+ return self.__collection__[-1]
def bottom_card(self):
- return self.collection[0]
+ return self.__collection__[0]
def add(self, card):
- self.collection.append(card)
+ self.__collection__.append(card)
def index(self, card):
- self.collection.index(card)
+ self.__collection__.index(card)
def __iter__(self):
- return iter(self.collection)
+ return iter(self.__collection__)
def __getitem__(self, index):
- return self.collection[index]
+ return self.__collection__[index]
def __len__(self):
- return len(self.collection)
+ return len(self.__collection__)
+
+ def __str__(self):
+ return str(self.__collection__)
+
+ def __repr__(self):
+ return repr(self.__coollection__)
def StandardDeck():
cards = [Card(RANKS[rank], SUITS[suit])
for rank, suit in product(RANK_NAMES, SUIT_NAMES)]
return CardCollection(cards)
def BeloteDeck():
excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
cards = [Card(RANKS[rank], SUITS[suit])
for rank, suit in product(RANK_NAMES, SUIT_NAMES)
if rank not in excluded_ranks]
return CardCollection(cards)
def SixtySixDeck():
excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
cards = [Card(RANKS[rank], SUITS[suit])
for rank, suit in product(RANK_NAMES, SUIT_NAMES)
if rank not in excluded_ranks]
return CardCollection(cards)

Веселин обнови решението на 25.03.2014 22:18 (преди около 10 години)

from itertools import product
class Rank:
def __init__(self):
self.symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.symbol
class Suit:
def __init__(self):
self.color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.color
RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
for symbol in RANK_NAMES}
SUITS = {color: type(color, (Suit,), dict(color=color))
for color in SUIT_NAMES}
class Card:
def __init__(self, rank, suit):
self.__rank__ = rank()
self.__suit__ = suit()
@property
def rank(self):
return self.__rank__
@property
def suit(self):
return self.__suit__
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return '{0} of {1}'.format(self.rank, self.suit)
def __repr__(self):
return '<Card {0}>'.format(str(self))
class CardCollection:
def __init__(self, collection=[]):
self.__collection__ = list(collection)
def draw(self, index):
return self.__collection__.pop(index)
def draw_from_top(self):
return self.__collection__.pop()
def draw_from_bottom(self):
return self.__collection__.pop(0)
def top_card(self):
return self.__collection__[-1]
def bottom_card(self):
return self.__collection__[0]
def add(self, card):
self.__collection__.append(card)
def index(self, card):
self.__collection__.index(card)
def __iter__(self):
return iter(self.__collection__)
def __getitem__(self, index):
return self.__collection__[index]
def __len__(self):
return len(self.__collection__)
def __str__(self):
return str(self.__collection__)
def __repr__(self):
- return repr(self.__coollection__)
+ return repr(self.__collection__)
+DECK = [Card(RANKS[rank], SUITS[suit])
+ for suit, rank in product(SUIT_NAMES, RANK_NAMES)]
+
+
def StandardDeck():
- cards = [Card(RANKS[rank], SUITS[suit])
- for rank, suit in product(RANK_NAMES, SUIT_NAMES)]
- return CardCollection(cards)
+ return CardCollection(DECK)
def BeloteDeck():
excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
- cards = [Card(RANKS[rank], SUITS[suit])
- for rank, suit in product(RANK_NAMES, SUIT_NAMES)
- if rank not in excluded_ranks]
+ cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)
def SixtySixDeck():
excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
- cards = [Card(RANKS[rank], SUITS[suit])
- for rank, suit in product(RANK_NAMES, SUIT_NAMES)
- if rank not in excluded_ranks]
+ cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)

Веселин обнови решението на 26.03.2014 01:01 (преди около 10 години)

from itertools import product
class Rank:
def __init__(self):
self.symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.symbol
class Suit:
def __init__(self):
self.color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.color
-RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
- 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
-SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
-RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
- for symbol in RANK_NAMES}
-SUITS = {color: type(color, (Suit,), dict(color=color))
- for color in SUIT_NAMES}
-
-
class Card:
def __init__(self, rank, suit):
- self.__rank__ = rank()
- self.__suit__ = suit()
+ self.__rank = rank()
+ self.__suit = suit()
@property
def rank(self):
- return self.__rank__
+ return self.__rank
@property
def suit(self):
- return self.__suit__
+ return self.__suit
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return '{0} of {1}'.format(self.rank, self.suit)
def __repr__(self):
return '<Card {0}>'.format(str(self))
class CardCollection:
def __init__(self, collection=[]):
- self.__collection__ = list(collection)
+ self.__collection = list(collection)
def draw(self, index):
- return self.__collection__.pop(index)
+ return self.__collection.pop(index)
def draw_from_top(self):
- return self.__collection__.pop()
+ return self.__collection.pop()
def draw_from_bottom(self):
- return self.__collection__.pop(0)
+ return self.__collection.pop(0)
def top_card(self):
- return self.__collection__[-1]
+ return self.__collection[-1]
def bottom_card(self):
- return self.__collection__[0]
+ return self.__collection[0]
def add(self, card):
- self.__collection__.append(card)
+ self.__collection.append(card)
def index(self, card):
- self.__collection__.index(card)
+ self.__collection.index(card)
def __iter__(self):
- return iter(self.__collection__)
+ return iter(self.__collection)
def __getitem__(self, index):
- return self.__collection__[index]
+ return self.__collection[index]
def __len__(self):
- return len(self.__collection__)
+ return len(self.__collection)
def __str__(self):
- return str(self.__collection__)
+ return str(self.__collection)
def __repr__(self):
- return repr(self.__collection__)
+ return repr(self.__collection)
-DECK = [Card(RANKS[rank], SUITS[suit])
- for suit, rank in product(SUIT_NAMES, RANK_NAMES)]
+RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
+ for symbol in RANK_NAMES}
+SUITS = {color: type(color, (Suit,), dict(color=color))
+ for color in SUIT_NAMES}
+DECK = [Card(RANKS[rank], SUITS[suit]) for suit, rank
+ in product(SUIT_NAMES, RANK_NAMES)]
def StandardDeck():
return CardCollection(DECK)
def BeloteDeck():
excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)
def SixtySixDeck():
excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)

Веселин обнови решението на 26.03.2014 15:15 (преди около 10 години)

from itertools import product
+SYMBOLS = ['K', 'Q', 'J', '10', '9', '8', '7', '6', '5', '4', '3', '2', 'A']
+COLORS = ['black', 'red', 'red', 'black']
+RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+def rank_symbol(rank):
+ return SYMBOLS[RANK_NAMES.index(rank)]
+
+
+def suit_color(suit):
+ return COLORS[SUIT_NAMES.index(suit)]
+
+
class Rank:
def __init__(self):
- self.symbol
+ self.rank
+ @property
+ def symbol(self):
+ return rank_symbol(self.rank)
+
def __eq__(self, other):
- return self.symbol == other.symbol
+ return self.rank == other.rank
def __str__(self):
- return self.symbol
+ return self.rank
class Suit:
def __init__(self):
- self.color
+ self.suit
+ @property
+ def color(self):
+ return suit_color(self.suit)
+
def __eq__(self, other):
- return self.color == other.color
+ return self.suit == other.suit
def __str__(self):
- return self.color
+ return self.suit
class Card:
def __init__(self, rank, suit):
self.__rank = rank()
self.__suit = suit()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
- return '{0} of {1}'.format(self.rank, self.suit)
+ return '{0} of {1}'.format(str(self.rank), str(self.suit))
def __repr__(self):
return '<Card {0}>'.format(str(self))
class CardCollection:
def __init__(self, collection=[]):
self.__collection = list(collection)
def draw(self, index):
return self.__collection.pop(index)
def draw_from_top(self):
return self.__collection.pop()
def draw_from_bottom(self):
return self.__collection.pop(0)
def top_card(self):
return self.__collection[-1]
def bottom_card(self):
return self.__collection[0]
def add(self, card):
self.__collection.append(card)
def index(self, card):
- self.__collection.index(card)
+ return self.__collection.index(card)
def __iter__(self):
return iter(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __len__(self):
return len(self.__collection)
def __str__(self):
return str(self.__collection)
def __repr__(self):
return repr(self.__collection)
-RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
- 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
-SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
-RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
- for symbol in RANK_NAMES}
-SUITS = {color: type(color, (Suit,), dict(color=color))
- for color in SUIT_NAMES}
+RANKS = {rank_name: type(rank_name, (Rank,), dict(rank=rank_name))
+ for rank_name in RANK_NAMES}
+SUITS = {suit_name: type(suit_name, (Suit,), dict(suit=suit_name))
+ for suit_name in SUIT_NAMES}
DECK = [Card(RANKS[rank], SUITS[suit]) for suit, rank
in product(SUIT_NAMES, RANK_NAMES)]
def StandardDeck():
return CardCollection(DECK)
def BeloteDeck():
excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)
def SixtySixDeck():
excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
cards = [card for card in DECK if str(card.rank) not in excluded_ranks]
return CardCollection(cards)