Guest User

Untitled

a guest
May 31st, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.88 KB | None | 0 0
  1. r = Random.new
  2.  
  3. # Bob picks randomly strat
  4. bobs_winnings = 0.0
  5. 10000.times do ||
  6.   b1 = r.rand # bag1
  7.   b2 = r.rand # bag2
  8.   # Doesn't matter what alice does, bob picks randomly
  9.   bobs_winnings += if r.rand > 0.5 then b1 else b2 end
  10. end
  11.  
  12. puts "Bob's winnings in 10k rounds always picking random: #{bobs_winnings}"
  13.  
  14. # Bob picks if the bag he's shown is > 0.5
  15. bobs_winnings = 0.0
  16. 10000.times do ||
  17.   b1 = r.rand # bag1
  18.   b2 = r.rand # bag2
  19.  
  20.   # alice shows him the bag nearer 0.5
  21.   bob_sees = if (b1 - 0.5).abs > (b2 - 0.1).abs then "b1" else "b2" end
  22.   other = if bob_sees == "b1" then "b2" else "b1" end
  23.  
  24.   if eval(bob_sees) > 0.5 then
  25.     # pick what bob saw
  26.     bobs_winnings += eval(bob_sees)
  27.   else
  28.     # Pick the opposite
  29.     bobs_winnings += eval(other)
  30.   end
  31. end
  32.  
  33. puts "Bob's winnings in 10k rounds always picking the bag if its value > 0.5: #{bobs_winnings}"
  34.  
Advertisement
Add Comment
Please, Sign In to add comment