88 lines
1.7 KiB
Plaintext
88 lines
1.7 KiB
Plaintext
ClearAll[Unload, Load, Spin, Fire]
|
|
Unload[] := ConstantArray[False, 6]
|
|
Load[state_List] := Module[{s = state},
|
|
While[s[[2]],
|
|
s = RotateRight[s, 1]
|
|
];
|
|
s[[2]] = True;
|
|
s
|
|
]
|
|
Spin[state_List] := RotateRight[state, RandomInteger[{1, 6}]]
|
|
Fire[state_List] := Module[{shot},
|
|
shot = First[state];
|
|
{RotateRight[state, 1], shot}
|
|
]
|
|
ClearAll[LSLSFSF]
|
|
LSLSFSF[] := Module[{state, shot},
|
|
state = Unload[];
|
|
state = Load[state];
|
|
state = Spin[state];
|
|
state = Load[state];
|
|
state = Spin[state];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
state = Spin[state];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
Return[False]
|
|
]
|
|
ClearAll[LSLSFF]
|
|
LSLSFF[] := Module[{state, shot},
|
|
state = Unload[];
|
|
state = Load[state];
|
|
state = Spin[state];
|
|
state = Load[state];
|
|
state = Spin[state];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
Return[False]
|
|
]
|
|
ClearAll[LLSFSF]
|
|
LLSFSF[] := Module[{state, shot},
|
|
state = Unload[];
|
|
state = Load[state];
|
|
state = Load[state];
|
|
state = Spin[state];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
state = Spin[state];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
Return[False]
|
|
]
|
|
ClearAll[LLSFF]
|
|
LLSFF[] := Module[{state, shot},
|
|
state = Unload[];
|
|
state = Load[state];
|
|
state = Load[state];
|
|
state = Spin[state];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
{state, shot} = Fire[state];
|
|
If[shot,
|
|
Return[True]
|
|
];
|
|
Return[False]
|
|
]
|
|
n = 10^5;
|
|
Count[Table[LSLSFSF[], n], True]/N[n]
|
|
Count[Table[LSLSFF[], n], True]/N[n]
|
|
Count[Table[LLSFSF[], n], True]/N[n]
|
|
Count[Table[LLSFF[], n], True]/N[n]
|