On Sat, Aug 23, 2008 at 4:35 PM, Matthew Moss <matthew.moss / gmail.com> wrote: > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > The three rules of Ruby Quiz 2: > > 1. Please do not post any solutions or spoiler discussion for this > quiz until 48 hours have passed from the time on this message. > > 2. Support Ruby Quiz 2 by submitting ideas as often as you can! (A > permanent, new website is in the works for Ruby Quiz 2. Until then, > please visit the temporary website at > > <http://splatbang.com/rubyquiz/>. > > 3. Enjoy! > > Suggestion: A [QUIZ] in the subject of emails about the problem > helps everyone on Ruby Talk follow the discussion. Please reply to > the original quiz message, if you can. > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > ## Uptime Since... (#174) > > > Nice and easy one this week. Your task is to write a Ruby script that > reports the date and time of your last reboot, making use of the > `uptime` command. My solution, tested in Ubuntu 8.04 and Fedora Core 2: uptime = (`uptime`.match /up (.*),.*user/)[1].delete(" ") captures = (uptime.match /((\d+)days,)?(\d+):(\d+)/).captures[1..-1] elapsed_seconds = captures.zip([86440, 3600, 60]).inject(0) do |total, (x,y)| total + (x.nil? ? 0 : x.to_i * y) end puts "Last reboot was on #{Time.now - elapsed_seconds}" Nice quiz !!! Jesus.