Class: MontyHallProblem::Doors

Inherits:
Object
  • Object
show all
Defined in:
lib/monty_hall_problem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size = 3) ⇒ Doors

Returns a new instance of Doors.



51
52
53
54
55
# File 'lib/monty_hall_problem.rb', line 51

def initialize(size=3)
  self.size = size
  self.door = Array.new(size) { false }
  self.opened_door_idx = []
end

Instance Attribute Details

#doorObject

Returns the value of attribute door.



48
49
50
# File 'lib/monty_hall_problem.rb', line 48

def door
  @door
end

#opened_door_idxObject

Returns the value of attribute opened_door_idx.



49
50
51
# File 'lib/monty_hall_problem.rb', line 49

def opened_door_idx
  @opened_door_idx
end

#sizeObject

Returns the value of attribute size.



47
48
49
# File 'lib/monty_hall_problem.rb', line 47

def size
  @size
end

Instance Method Details

#car_door_idxObject



66
67
68
# File 'lib/monty_hall_problem.rb', line 66

def car_door_idx
  door.map.with_index{ |e, i| i if !!e  }.compact
end

#no_car_door_idxObject



70
71
72
# File 'lib/monty_hall_problem.rb', line 70

def no_car_door_idx
  door.map.with_index{ |e, i| i if !e  }.compact
end

#put(door_idx) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/monty_hall_problem.rb', line 57

def put(door_idx)
  if door[door_idx]
    return false
  else
    door[door_idx] = true
    return true
  end
end