Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Last active September 30, 2024 23:12
Show Gist options
  • Save JosiahParry/5ae177f191112fd15d91410278e28588 to your computer and use it in GitHub Desktop.
Save JosiahParry/5ae177f191112fd15d91410278e28588 to your computer and use it in GitHub Desktop.
Blackwell's N=2
[package]
name = "my-hands"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
rand_distr = "0.4.3"
use rand::{rngs::ThreadRng, Rng};
use rand_distr::StandardNormal;
fn simulate_range(rng: &mut ThreadRng) -> bool {
let x1: i128 = rng.gen();
let x2: i128 = rng.gen();
let r = rng.sample::<f64, StandardNormal>(StandardNormal) as i128;
let choice = if r > x1 { x2 } else { x1 };
choice >= x1.max(x2)
}
fn main() {
let mut rng = rand::thread_rng();
let n = 1000;
let res = (0..n)
.into_iter()
.fold(0, |acc, _| acc + simulate_range(&mut rng) as i32);
println!("prop success: {}", (res as f64) / (n as f64));
}
sim <- function() {
x <- floor(runif(2, max = 100))
r <- rnorm(1, mean = 50)
idx <- ifelse(x[1] < r, 2, 1)
choice <- x[idx]
choice >= max(x)
}
nsim <- 10000
sum(replicate(nsim, sim())) / nsim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment