- generate deck
- create cards
1 PHP[ | ]
PHP
Copy
$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[ | ]
Python
Copy
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
Python
Copy
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 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- Python (25)
- PHP (8)
리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― Jmnote리눅스 Python 2.7 컴파일 설치 ― ㅇㅇㅇ미운코딩새끼 ― 승호 도령미운코딩새끼 ― 불탄고등어미운코딩새끼 ― 김레이미운코딩새끼 ― 호박이미운코딩새끼 ― Junhg0211미운코딩새끼 ― 김왼손미운코딩새끼 ― 용딘이미운코딩새끼 ― Pinkcrimson유기농냠냠파이썬 ― 호박유기농냠냠파이썬 ― 이에스유기농냠냠파이썬 ― 이승현파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong