Module Module1 Sub Main() ''乱数のタネの初期化 Randomize() Dim rep As Integer '繰り返し回数を数える変数 Dim N As Integer '何回繰り返すか Dim ok As Integer '7つ揃った回数 Dim sumCount As Integer '1試行あたり何個揃ったかの合計 Dim NofCom As Integer 'コミュニティが全部でいくつあるか Dim Sokonuke As Integer '底抜けコミュの数 Dim Disp As Boolean ''設定のデフォルト値 N = 1000 NofCom = 44 Sokonuke = 7 ''何回やるか聞く Dim RL As String Console.WriteLine("何試行やりますか? (デフォルト: 1,000)") RL = Console.ReadLine() If IsNumeric(RL) Then N = RL End If Console.WriteLine("コミュニティは全部でいくつありますか? (デフォルト: 44)") RL = Console.ReadLine If IsNumeric(RL) Then NofCom = RL End If Console.WriteLine("底抜けコミュは全部でいくつありますか? (デフォルト: 7)") RL = Console.ReadLine If IsNumeric(RL) Then Sokonuke = RL End If ''全コミュニティ数よりも底抜けコミュの数が多いバカ者はここで止める。 If Sokonuke > NofCom Then Console.WriteLine("底抜けにぃ〜、矛盾してまんがな(全コミュニティ数より[底抜け]が多い)") Console.WriteLine("See you A'gain!") End End If ''画面表示するか聞く Disp = True Console.WriteLine("途中経過を見ない場合は N を入力") If UCase(Console.ReadLine) = "N" Then Disp = False ok = 0 sumCount = 0 Do While rep < n rep = rep + 1 ''配列初期設定 Dim ar(NofCom + 1) As Char Dim i As Integer For i = 1 To NofCom If i <= Sokonuke Then ar(i) = "*" Else ar(i) = "-" End If Next ''配列をランダムに並び替える Dim sw As Char Dim r As Integer For i = 1 To NofCom r = Int(Rnd() * NofCom) + 1 sw = ar(i) ar(i) = ar(r) ar(r) = sw Next Dim count As Integer count = 0 ''とりあえず表示 If Disp = True Then Console.Write(rep & " ") For i = 1 To NofCom Console.Write(ar(i)) If i < 10 And ar(i) = "*" Then count = count + 1 End If If i = 9 Then Console.Write("|") End If Next If count = Sokonuke Then ok = ok + 1 Console.Write(" OK (" & count & ") これまでの成功 " & ok & vbNewLine) Else Console.Write(" NG (" & count & ") これまでの成功 " & ok & vbNewLine) End If Else ''画面表示しない場合。何の工夫も無い、タコなプログラムで御免 For i = 1 To NofCom If i < 10 And ar(i) = "*" Then count = count + 1 End If Next If count = Sokonuke Then ok = ok + 1 End If End If sumCount = sumCount + count Loop Dim dig As String dig = "##0." dig = dig.PadRight(Int(Math.Log10(rep)) + 3, "0") Console.WriteLine(rep & "回中、トップに" & Sokonuke & "個全てが揃うのは" & ok & "回 (確率: " & Format(ok / rep * 100, dig) & "%) 平均個数は" & Format(sumCount / rep, dig)) End Sub End Module