Generate deck

generate deck
create cards

1 PHP[ | ]

$suits = array('spade','heart','diamond','clover');
$ranks = array_merge(array('A'), range(2, 11), array('J', 'Q', 'K' ));
$deck = array();
foreach( $suits as $suit ) {
	foreach( $ranks as $rank ) {
		$deck[] = array($suit, $rank);
	}
}
print_r( $deck );
echo count($deck);
# Array
# (
#     [0] => Array
#         (
#             [0] => spade
#             [1] => A
# ... (생략)
#     [55] => Array
#         (
#             [0] => clover
#             [1] => K
#         )
#
# )
# 56

2 Python[ | ]

suits = ['spade','heart','diamond','clover']
ranks = ['A'] + list(range(2, 11)) + ['J','Q','K']
deck = []
for suit in suits:
    for rank in ranks:
        deck.append( (suit, rank) )
print( deck )
print( len(deck) )
# [('spade', 'A'), ('spade', 2), ('spade', 3), ('spade', 4), ('spade', 5), ('spade', 6), ('spade', 7), ('spade', 8), ('spade', 9), ('spade', 10), ('spade', 'J'), ('spade', 'Q'), ('spade', 'K'), ('heart', 'A'), ('heart', 2), ('heart', 3), ('heart', 4), ('heart', 5), ('heart', 6), ('heart', 7), ('heart', 8), ('heart', 9), ('heart', 10), ('heart', 'J'), ('heart', 'Q'), ('heart', 'K'), ('diamond', 'A'), ('diamond', 2), ('diamond', 3), ('diamond', 4), ('diamond', 5), ('diamond', 6), ('diamond', 7), ('diamond', 8), ('diamond', 9), ('diamond', 10), ('diamond', 'J'), ('diamond', 'Q'), ('diamond', 'K'), ('clover', 'A'), ('clover', 2), ('clover', 3), ('clover', 4), ('clover', 5), ('clover', 6), ('clover', 7), ('clover', 8), ('clover', 9), ('clover', 10), ('clover', 'J'), ('clover', 'Q'), ('clover', 'K')]
# 52
suits = ['spade','heart','diamond','clover']
ranks = ['A'] + list(range(2, 11)) + ['J','Q','K']
deck = [(s, r) for s in suits for r in ranks]
print( deck )
print( len(deck) )
# [('spade', 'A'), ('spade', 2), ('spade', 3), ('spade', 4), ('spade', 5), ('spade', 6), ('spade', 7), ('spade', 8), ('spade', 9), ('spade', 10), ('spade', 'J'), ('spade', 'Q'), ('spade', 'K'), ('heart', 'A'), ('heart', 2), ('heart', 3), ('heart', 4), ('heart', 5), ('heart', 6), ('heart', 7), ('heart', 8), ('heart', 9), ('heart', 10), ('heart', 'J'), ('heart', 'Q'), ('heart', 'K'), ('diamond', 'A'), ('diamond', 2), ('diamond', 3), ('diamond', 4), ('diamond', 5), ('diamond', 6), ('diamond', 7), ('diamond', 8), ('diamond', 9), ('diamond', 10), ('diamond', 'J'), ('diamond', 'Q'), ('diamond', 'K'), ('clover', 'A'), ('clover', 2), ('clover', 3), ('clover', 4), ('clover', 5), ('clover', 6), ('clover', 7), ('clover', 8), ('clover', 9), ('clover', 10), ('clover', 'J'), ('clover', 'Q'), ('clover', 'K')]
# 52

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}