Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2009 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6b5bed12e18932e5bf9f to your computer and use it in GitHub Desktop.
Save anonymous/6b5bed12e18932e5bf9f to your computer and use it in GitHub Desktop.
Pankaj Sisodiya
=begin
Hi, This is Pankaj Sisodiya. I Love Programming.
I am very new to Ruby. I can't write the code for this program in Ruby, in exactly the manner you people need.
I am not aware of classes & syntax of Ruby & so can't create a function in Ruby which can take n number of parameters.
But i did try to solve your problem.
Let me tell you what i did:
1. set expectedtime (this is fixed)
2. set different arrival times (delayed time)
3. find the difference between each arrival times & expectedtime
4. now sum all the diferences (i don't how its returning on minutes, from a Riby tutorial I found that when we make difference between two Time in Ruby, it returns us Seconds)
5. take average
6. averagetime = expectedtime + average
7. display averagetime
=end
expectedtime = Time.new
arrivedtime1 = Time.new
arrivedtime2 = Time.new
arrivedtime3 = Time.new
arrivedtime4 = Time.new
expectedtime = Time.local(2009,10,15,10,0,0)
arrivedtime1 = Time.local(2009,10,15,11,51,0)
arrivedtime2 = Time.local(2009,10,15,11,56,0)
arrivedtime3 = Time.local(2009,10,15,12,1,0)
arrivedtime4 = Time.local(2009,10,15,12,6,0)
arrivedtime5 = Time.local(2009,10,15,12,11,0)
d1 = (arrivedtime1 - expectedtime).to_i
d2 = (arrivedtime2 - expectedtime).to_i
d3 = (arrivedtime3 - expectedtime).to_i
d4 = (arrivedtime4 - expectedtime).to_i
d5 = (arrivedtime5 - expectedtime).to_i
puts d1,d2,d3,d4,d5
avg = (d1+d2+d3+d4+d5)/5
puts avg
avgtime = Time.new
avgtime = expectedtime + avg
puts avgtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment