Programming challenge

Hans Fugal hans at fugal.net
Fri Sep 28 09:57:18 MDT 2007


On Thu, 27 Sep 2007 at 15:44 -0600, Sasha Pachev wrote:
> Reward: public exposure of your skills, increased pool of references
> when trying to get a hot job, possibly a good job offer from somebody
> on the PLUG.

And don't forget public nit-picking, humiliation, and beratement. ;-)

15 minutes, including looking up the documentation for regexp stuff I
wasn't sure about and testing and rewriting and blowing my nose and
getting a drink of water. (Ruby)

def secondize(str)
  while str =~ /((\d+):)?(\d+):([\d.]+)/
    s = $4.to_f
    s += $3.to_i*60
    s += $2.to_i*60*60 if $2
    str = "#{$`}#{s}#{$'}"
  end
  str
end

# tests
['8:12','10:12:33', '5 + 3*6:50', '8 / 13*15:32:20.4 - 10'].each do |e|
  puts "#{e} -> #{secondize(e)}"
end

-- 
Hans Fugal ; http://hans.fugal.net
 
There's nothing remarkable about it. All one has to do is hit the 
right keys at the right time and the instrument plays itself.
    -- Johann Sebastian Bach



More information about the PLUG mailing list