Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
No point on changing the door
prng = Random.new
on_3 = 0
on_2 = 0
on_1 = 0
total = 100000
partial = 0
total_changes = 0
correct_after_change = 0
wrong_after_change = 0
correct_without_change = 0
wrong_without_change = 0
(1..total).each do |i|
door = []
door[0] = false
door[1] = false
door[2] = false
door[prng.rand(0..2)] = true
#selected = prng.rand(0..2)
selected = 0
# puts "Door selected is #{selected + 1}"
if door[2]
on_3 += 1
else
partial += 1
if door[1]
on_2 += 1
else
on_1 += 1
end
change = prng.rand(0..1)
if (change == 1)
total_changes += 1
selected += change
# puts "changed selection"
end
if door[selected] && change == 1
correct_after_change += 1
elsif !door[selected] && change == 1
wrong_after_change += 1
elsif door[selected]
correct_without_change += 1
else
wrong_without_change += 1
end
end
end
puts "on door 1: #{on_1}"
puts "on door 2: #{on_2}"
puts "on door 3: #{on_3}"
puts "percentage on door 1: #{on_1 * 100.0 / total}"
puts "percentage on door 2: #{on_2 * 100.0 / total}"
puts "percentage on door 3: #{on_3 * 100.0 / total}"
puts ""
puts "correct after change: #{correct_after_change}"
puts "wrong after change: #{wrong_after_change}"
puts "correct without change: #{correct_without_change}"
puts "wrong without change: #{wrong_without_change}"
puts ""
puts "total changes: #{total_changes}"
puts "percentage changes: #{total_changes * 100.0 / partial}"
puts ""
puts "percentage on correct after change: #{correct_after_change * 100.0 / partial}"
puts "percentage on wrong after change: #{wrong_after_change * 100.0 / partial}"
puts "percentage on correct without change: #{correct_without_change * 100.0 / partial}"
puts "percentage on wrong without change: #{wrong_without_change * 100.0 / partial}"
puts ""
puts "percentage of changes correct: #{correct_after_change * 100.0 / total_changes}"
puts "percentage of changes wrong: #{wrong_after_change * 100.0 / total_changes}"
puts "percentage of no changes correct: #{correct_without_change * 100.0 / (partial - total_changes)}"
puts "percentage of no changes wrong: #{wrong_without_change * 100.0 / (partial - total_changes)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment