回答編集履歴
2
追記
answer
CHANGED
@@ -54,4 +54,6 @@
|
|
54
54
|
**実行結果** [Wandbox](https://wandbox.org/permlink/0D3yer2vY5ZmBopN)
|
55
55
|
```plain
|
56
56
|
7萬 1筒 4筒 9筒 2索 3索 9索 東 東 西 白 白 中
|
57
|
-
```
|
57
|
+
```
|
58
|
+
|
59
|
+
実際にはcollections.dequeあたりを使った方が牌の重複などトラブルは起きづらいでしょう。
|
1
追記
answer
CHANGED
@@ -7,4 +7,51 @@
|
|
7
7
|
```
|
8
8
|
|
9
9
|
yamahai[0,1]と書けば0番目と1番目を取り出せる...
|
10
|
-
**なんて便利機能は無いからです。存在しない文法を使ってはいけません。**
|
10
|
+
**なんて便利機能は無いからです。存在しない文法を使ってはいけません。**
|
11
|
+
|
12
|
+
おまけ
|
13
|
+
---
|
14
|
+
すごく雑な実装でも良ければこんなふうにも書けます。
|
15
|
+
```Python
|
16
|
+
import random
|
17
|
+
|
18
|
+
|
19
|
+
def make_pieces():
|
20
|
+
pieces = ['東', '南', '西', '北', '白', '發', '中']
|
21
|
+
pieces += [
|
22
|
+
'{}{}'.format(n, k)
|
23
|
+
for n in range(1, 10)
|
24
|
+
for k in ['萬', '筒', '索']
|
25
|
+
]
|
26
|
+
|
27
|
+
return 4 * pieces
|
28
|
+
|
29
|
+
|
30
|
+
def key_for_piece(piece):
|
31
|
+
honors = ['東', '南', '西', '北', '白', '發', '中']
|
32
|
+
if piece in honors:
|
33
|
+
return 90 + honors.index(piece)
|
34
|
+
|
35
|
+
#
|
36
|
+
simples = ['萬', '筒', '索']
|
37
|
+
num, simple = piece
|
38
|
+
|
39
|
+
return simples.index(simple) * 10 + int(num)
|
40
|
+
|
41
|
+
|
42
|
+
def print_pieces(pieces):
|
43
|
+
pieces = sorted(pieces, key=key_for_piece)
|
44
|
+
print(*pieces)
|
45
|
+
|
46
|
+
|
47
|
+
pieces = make_pieces()
|
48
|
+
random.shuffle(pieces)
|
49
|
+
|
50
|
+
hand = pieces[:13]
|
51
|
+
print_pieces(hand)
|
52
|
+
```
|
53
|
+
|
54
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/0D3yer2vY5ZmBopN)
|
55
|
+
```plain
|
56
|
+
7萬 1筒 4筒 9筒 2索 3索 9索 東 東 西 白 白 中
|
57
|
+
```
|