BVB Source Codes

Algorithm-Implementations Show monty_hall.rb Source code

Return Download Algorithm-Implementations: download monty_hall.rb Source code - Download Algorithm-Implementations Source code - Type:.rb
  1. class MontyHall
  2.   def self.simulate(ndoors, switch = nil)
  3.         prng = Random.new
  4.         winning_door = prng.rand(1..ndoors)
  5.         choice = prng.rand(1..ndoors)
  6.         doors = (1..ndoors).to_a
  7.  
  8.         while doors.size > 2
  9.           door_to_open_index = prng.rand(1..doors.size)
  10.           door_to_open = doors[door_to_open_index]
  11.  
  12.           if door_to_open == winning_door and door_to_open = choice
  13.                 doors.delete_at(door_to_open_index)
  14.           end
  15.         end
  16.  
  17.         if switch
  18.           choice = (doors[1] == choice and doors[2] or doors[1])
  19.         end
  20.  
  21.         # returns true if users wins
  22.         return choice == winning_door
  23.   end
  24. end
  25.  
  26. p MontyHall.simulate(3, true)
downloadmonty_hall.rb Source code - Download Algorithm-Implementations Source code
Related Source Codes/Software:
raty - 2017-04-22
RDVTabBarController - Highly customizable tabBar and tabBarController fo... 2017-04-22
material-icon-lib - Library containing over 1500 material vector icons... 2017-04-21
httpdiff - Perform the same request against two HTTP servers ... 2017-04-21
jquerytools - The missing UI library for the Web ... 2017-04-21
mcrouter - Mcrouter is a memcached protocol router for scalin... 2017-04-22
dynomite - A generic dynamo implementation for different k-v ... 2017-04-22
kityminder - Baidu brain figure 2017-04-22
llvm - Mirror of official llvm git repository located at ... 2017-04-22
RBBAnimation - Block-based animations made easy, comes with easin... 2017-04-22
ied - 2017-04-29
Nimble - A Matcher Framework for Swift and Objective-C 2017-04-29
MHVideoPhotoGallery - A Photo and Video Gallery 2017-04-29
shoulda-matchers - Collection of testing matchers extracted from Shou... 2017-04-29
Android-SlideExpandableListView - A better ExpandableListView, with animated expanda... 2017-04-29
AppSales-Mobile - App Sales allows iPhone and Mac App Store develope... 2017-04-29
react-templates - Light weight templates for react ... 2017-04-28
afterglow-theme - A minimal dark Theme for Sublime Text 2 and 3 2017-04-28
jwt-go - Golang implementation of JSON Web Tokens (JWT) 2017-04-28
DeerResume - Tool MarkDown online resume, online preview, edit,... 2017-04-28

 Back to top