conv.py
The snippet can be accessed without any authentication.
Authored by
Anton Bela Büttner
Convert the piles in string representation to id representation. i.e.:
$ ./id_calc.py '♦B, ♣K, ♦7, ♦10, ♠D, ♠8, ♣B, ♣D, ♥A, ♥8, ♣7, ♠7, ♠A, ♥B, ♣9'
> {16, 27, 0, 12, 22, 6, 19, 23, 29, 5, 3, 2, 30, 17, 11}
conv.py 719 B
#!/usr/bin/env python3
import sys
def convert(kind: str, rank: str) -> int:
kind_table = {
'♦': 0,
'♥': 1,
'♠': 2,
'♣': 3
}
if rank == 'A':
rank = 14
elif rank == 'K':
rank = 13
elif rank == 'D':
rank = 12
elif rank == 'B':
rank = 11
else:
rank = int(rank)
return kind_table[kind] + (rank - 7) * 4
def parse_card(s: str) -> (str, int):
return s[:1], s[1:]
cards = sys.argv[1]
cards = cards.replace(' ', '').split(',')
converted = []
for card in cards:
kind, rank = parse_card(card)
converted.append(convert(kind, rank))
print('{', end='')
print(*converted, sep=', ', end='')
print('}')
Please register or sign in to comment