Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.71 KB | None | 0 0
  1. =begin
  2. We required a module for patients control on a clinic. All patients must register upon arrival the system add this patient to a queue,
  3. display his number. Create a method for pull out.
  4. =end
  5. class PatientsQueue
  6.     @q = []
  7.   def register(patient_info)
  8.     @q.push patient_info
  9.     puts @q.size
  10.   end
  11.  
  12.   def get_current_patient
  13.     @q.shift
  14.   end
  15. end
  16.  
  17. =begin
  18. Create a method that receives an array of 100,000 integers and outputs the frequency with which each integer appears in ascending order
  19.  input: array = [1,2,4,5,6,8,2,5,3]
  20.  output: array = [1,1] [2,2] [3,1] [4,1] [5,2] [6,1] [8,1]
  21. =end
  22.  
  23. def get_frequency(integers)
  24.   integers.each_with_object(Hash.new(0)) {|key, hash| hash[key] += 1}
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement