SHARE
TWEET

Untitled

a guest Oct 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::env;
  2.  
  3. use solutions::class::Counter;
  4. use rand::distributions::{Bernoulli, Distribution};
  5.  
  6. fn main() {
  7.     let t: u64 = env::args().nth(1).unwrap().parse().unwrap();
  8.     let mut heads: Counter = Counter::new("heads");
  9.     let mut tails: Counter = Counter::new("tails");
  10.     for _ in 0..t {
  11.         let b = Bernoulli::new(0.5).unwrap();
  12.         if b.sample(&mut rand::thread_rng()) {
  13.             heads.increase();
  14.         } else {
  15.             tails.increase();
  16.         }
  17.     }
  18.     if heads.tally == tails.tally {
  19.         println!("Tie");
  20.     } else {
  21.         println!("{:?} wins", Counter::max(heads, tails));
  22.     }
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top