〓Mathematica〓
レス数が900を超えています。1000を超えると表示できなくなるよ。
0924132人目の素数さん
NGNG実験のフレームワークと1番目の解答まで書いてみよう。
(* GetBall : get a ball from the vase given as the args. *)
GetBall[Vase[nTotal_Integer, nRed_Integer]] :=
If[Random[Integer, {1, nTotal}] <= nRed, Red, Black]
(* Onestep : {n, n-th vase} -> {n+1, (n+1)-th vase} *)
OneStep[{nth_Integer, v : Vase[nTotal_, nRed_]}] := {nth +
1, (#[v] &) /@ Table[GetBall, {i, nTotal}] //
Vase[nTotal, Count[#, Red]] &}
(* Trial returns {iFix, fixColor} *)
Trial[nTotal_, nRed0_] :=
NestWhile[OneStep, {1, Vase[nTotal, nRed0]},
#[[2, 2]] != 0 && #[[2, 2]] != nTotal &] /. {Vase[nTotal, 0] -> Black,
Vase[nTotal, nTotal] -> Red}
(* pRed *)
pRed[trys_][nTotal_, nRed0_] :=
Count[Table[Trial[nTotal, nRed0], {trys}], {_, Red}] / trys // N
レス数が900を超えています。1000を超えると表示できなくなるよ。