質問編集履歴
3
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,6 +54,77 @@
|
|
54
54
|
|
55
55
|
本当に初心者なので、質問以外にもおかしな点などありましたら教えて頂けるとありがたいです。よろしくお願いします。
|
56
56
|
|
57
|
+
### 追記
|
57
|
-
|
58
|
+
can110さんのコードを使って下のように変更しました。
|
59
|
+
```Python
|
60
|
+
import random
|
58
61
|
|
62
|
+
seat_1 = [2,3,4,5,6,7,8,12,13,15,19,22,30,31]
|
63
|
+
seat_2 = [2,3,4,5,6,7,8,13,15,16,19,20,22,25,26,30,31,36]
|
64
|
+
seat_3 = [2,4,6,7,8,14,15,16,20,25,26,30,33,36,37]
|
65
|
+
seat_4 = [1,2,4,6,7,8,14,15,16,17,20,23,25,26,28,30,33,36,37]
|
66
|
+
seat_5 = [1,2,4,6,7,8,14,16,17,20,23,25,26,28,30,33,36,37]
|
67
|
+
seat_6 = [29]
|
68
|
+
seat_7 = [2,3,6,7,8,10,15,16,19,22,25,30,31,36]
|
69
|
+
seat_8 = [2,6,7,8,10,14,15,16,25,30,33,36,37]
|
70
|
+
seat_9 = [1,2,6,7,8,10,14,15,16,17,23,25,28,30,33,36,37]
|
71
|
+
seat_10 = [1,2,6,7,8,14,16,17,23,25,28,30,32,33,36,37]
|
72
|
+
seat_11 = [1,2,4,6,7,8,14,16,17,18,23,28,30,32,33,34,37]
|
73
|
+
seat_12 = [5,6,7,8,12,13,22,30,31]
|
74
|
+
seat_13 = [5,6,7,8,13,22,30,31]
|
75
|
+
seat_14 = [6,7,8,10,16,22,30,31]
|
76
|
+
seat_15 = [6,7,8,10,14,16,21,30,33,37]
|
77
|
+
seat_16 = [1,6,7,8,10,14,16,17,21,23,28,30,33,37]
|
78
|
+
seat_17 = [1,6,7,8,14,16,17,21,23,28,30,33,37]
|
79
|
+
seat_18 = [1,4,6,7,8,14,16,17,18,23,28,30,32,33,34,37]
|
80
|
+
seat_19 = [5,6,7,8,12,13,22,30]
|
81
|
+
seat_20 = [5,6,7,8,13,22,24,30]
|
82
|
+
seat_21 = [6,7,8,10,16,22,24,30]
|
83
|
+
seat_22 = [6,7,8,10,14,16,21,30,33,37]
|
84
|
+
seat_23 = [1,6,7,8,10,14,16,17,21,23,28,30,33,37]
|
85
|
+
seat_24 = [1,6,7,8,14,16,17,21,23,28,30,33,37]
|
86
|
+
seat_25 = [1,4,6,7,8,14,16,17,18,23,28,30,32,33,34,37]
|
87
|
+
seat_26 = [5,6,7,8,12,13,22,30]
|
88
|
+
seat_27 = [5,6,7,8,13,22,24,30]
|
89
|
+
seat_28 = [6,7,8,10,16,22,24,30]
|
90
|
+
seat_29 = [6,7,8,10,14,16,24,30,33,37]
|
91
|
+
seat_30 = [1,6,7,8,10,14,16,17,23,28,30,33,37]
|
92
|
+
seat_31 = [1,6,7,8,14,16,17,23,28,30,33,37]
|
93
|
+
seat_32 = [1,4,6,7,8,14,16,17,18,23,28,30,32,33,34,37]
|
94
|
+
seat_33 = [4,5,6,7,8,13,22,24,27,30]
|
95
|
+
seat_34 = [27]
|
96
|
+
seat_35 = [11]
|
97
|
+
seat_36 = [9]
|
98
|
+
seat_37 = [35]
|
99
|
+
|
100
|
+
|
101
|
+
seats = [seat_1,seat_2,seat_3,seat_4,seat_5,
|
102
|
+
seat_6,seat_7,seat_8,seat_9,seat_10,
|
103
|
+
seat_11,seat_12,seat_13,seat_14,seat_15,
|
104
|
+
seat_16,seat_17,seat_18,seat_19,seat_20,
|
105
|
+
seat_21,seat_22,seat_23,seat_24,seat_25,
|
106
|
+
seat_26,seat_27,seat_28,seat_29,seat_30,
|
107
|
+
seat_31,seat_32,seat_33,seat_34,seat_35,
|
108
|
+
seat_36,seat_37]
|
109
|
+
|
110
|
+
# (席番号, 候補リスト)に整形
|
111
|
+
seats = [(i+1,v) for i,v in enumerate(seats)]
|
112
|
+
|
113
|
+
ret = []
|
114
|
+
while seats:
|
115
|
+
# 候補の少ない席から抽選する
|
116
|
+
i = seats.index(min(seats, key=lambda v:len(v[1])))
|
117
|
+
seat = seats.pop(i) # popによって今から抽選する席番号は取り除かれる
|
118
|
+
|
119
|
+
# 抽選
|
120
|
+
person = random.choice(seat[1]) # 当選した人番号
|
121
|
+
|
122
|
+
# 結果を保存
|
123
|
+
ret.append((seat[0], person)) # (席番号, 人番号)
|
124
|
+
|
59
|
-
|
125
|
+
# 各席から当選した人を取り除く
|
126
|
+
seats = [ (seat[0], [p for p in seat[1] if p != person]) for seat in seats]
|
127
|
+
|
128
|
+
ret.sort(key=lambda v:v[0]) # 結果を席番号順に
|
129
|
+
print(ret)
|
130
|
+
```
|
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,10 +7,8 @@
|
|
7
7
|
|
8
8
|
### 発生している問題・エラーメッセージ
|
9
9
|
実行してみると表示されたリストに普通に重複が含まれており、何回実行しても重複のないリストが得られません。
|
10
|
-
```
|
11
|
-
エラーメッセージ
|
12
|
-
```
|
13
10
|
|
11
|
+
|
14
12
|
###
|
15
13
|
|
16
14
|
```Python
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
```Python
|
17
17
|
import random
|
18
18
|
|
19
|
-
seat_1 = [2,4,5,6]
|
19
|
+
seat_1 = [1,2,4,5,6]
|
20
20
|
seat_2 = [1,2,3,4,5,6]
|
21
21
|
seat_3 = [1,2,5,6]
|
22
22
|
seat_4 = [1,2,3]
|
@@ -36,8 +36,8 @@
|
|
36
36
|
random.choice(seats[num])
|
37
37
|
result.append(random.choice(seats[num]))
|
38
38
|
return result
|
39
|
-
|
40
|
-
|
39
|
+
|
40
|
+
|
41
41
|
#重複がない場合にTrue になる関数を定義
|
42
42
|
def no_duplicates(seq):
|
43
43
|
return len(seq) == len(set(seq))
|