Wednesday, August 21, 2013

Coderbyte: Time Convert (Ruby)

PROBLEM

Have the function TimeConvert(num) take the num parameter being passed and return the number of hours and minutes the parameter converts to (ie. if num = 63 then the output should be 1:3). Separate the number of hours and minutes with a colon.

SOLUTION

def TimeConvert(num)
    hour = num/60.round
    minute = num % 60
    return "#{hour}:#{minute}"
end
  
print TimeConvert(STDIN.gets)