-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
executable file
·35 lines (26 loc) · 877 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
require './prisoner.rb'
require './prison.rb'
class Simulation
@@simulation_length = 1_000_000
def simulate(search_method)
results = (1..@@simulation_length).map do
prison = Prison.new
prison.challenge_succeeded?(search_method)
end
passed = results.count(true)
pass_rate = passed.fdiv(results.length) * 100
puts "#{passed} prisons succeeded out of #{results.length}. For a pass rate of #{pass_rate.round(2)}%"
end
def simulate_random_search
puts "Beginning random search challenge"
self.simulate :found_in_random_search?
end
def simulate_cycle_search
puts "Beginning cycle search challenge"
self.simulate :found_in_cycle?
end
end
simulation = Simulation.new
simulation.simulate_random_search
simulation.simulate_cycle_search