Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
29
Task/Monty-Hall-problem/Zig/monty-hall-problem.zig
Normal file
29
Task/Monty-Hall-problem/Zig/monty-hall-problem.zig
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const std = @import("std");
|
||||
|
||||
const number_of_simulations: u32 = 10_000_000;
|
||||
|
||||
pub fn main() !void {
|
||||
var stick_wins: u32 = 0;
|
||||
var switch_wins: u32 = 0;
|
||||
var doors = [3]bool{ true, false, false };
|
||||
|
||||
var t = std.rand.DefaultPrng.init(42);
|
||||
const r = t.random();
|
||||
|
||||
var guess: u8 = undefined;
|
||||
var door_shown: u8 = undefined;
|
||||
|
||||
for (0..number_of_simulations) |_| {
|
||||
std.rand.Random.shuffle(r, bool, &doors);
|
||||
guess = r.intRangeAtMost(u8, 0, 2);
|
||||
door_shown = r.intRangeAtMost(u8, 0, 2);
|
||||
while (!doors[door_shown] and door_shown != guess) door_shown = r.intRangeAtMost(u8, 0, 2);
|
||||
if (doors[guess]) {
|
||||
stick_wins += 1;
|
||||
} else {
|
||||
switch_wins += 1;
|
||||
}
|
||||
}
|
||||
|
||||
std.debug.print("After {} simulations:\nStick wins: {}\nSwitch wins: {}\n", .{ number_of_simulations, stick_wins, switch_wins });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue