Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- r = Random.new
- # Bob picks randomly strat
- bobs_winnings = 0.0
- 10000.times do ||
- b1 = r.rand # bag1
- b2 = r.rand # bag2
- # Doesn't matter what alice does, bob picks randomly
- bobs_winnings += if r.rand > 0.5 then b1 else b2 end
- end
- puts "Bob's winnings in 10k rounds always picking random: #{bobs_winnings}"
- # Bob picks if the bag he's shown is > 0.5
- bobs_winnings = 0.0
- 10000.times do ||
- b1 = r.rand # bag1
- b2 = r.rand # bag2
- # alice shows him the bag nearer 0.5
- bob_sees = if (b1 - 0.5).abs > (b2 - 0.1).abs then "b1" else "b2" end
- other = if bob_sees == "b1" then "b2" else "b1" end
- if eval(bob_sees) > 0.5 then
- # pick what bob saw
- bobs_winnings += eval(bob_sees)
- else
- # Pick the opposite
- bobs_winnings += eval(other)
- end
- end
- puts "Bob's winnings in 10k rounds always picking the bag if its value > 0.5: #{bobs_winnings}"
Advertisement
Add Comment
Please, Sign In to add comment