All pastes #2031603 Raw Edit

loomsen

public shellscript v1 · immutable
#2031603 ·published 2010-12-28 18:10 UTC
rendered paste body
#Purpose: Convert time from yrs, days, hrs, mins to total minutes for a given planet#Contract: time_in_minutes(yr,da,hr,min): Int,Int,Int,Int,Symbol -> Int#Example: time_in_minutes(10) -> 0 years, 0 days, 0 hours, 10 minutes; convert_time(70) -> 0yrs, 0days, 1hours, 10 minutes#Exceptions: time_in_minutes('10')#require 'TestTimeInMin1'def daysPerYear(planet)  if (planet==:earth)    return 365  end  if planet==:saturn    return 30*365  endenddef hoursPerDay(planet)  if planet==:earth    return 24  end  if planet==:saturn    return 12  endenddef minutesPerHour  60enddef time_in_minutes(years,days,hours,mins,planet)  if not planet.is_a?(Symbol)    raise "Illegal Arg Value"  end    if not (natural?(years) and    natural?(days) and    natural?(hours) and    natural?(mins)    )    then raise "Illegal Arg Value"  end   #compute result  hours_in_minutes(days_in_hours(years_in_days(years,planet),planet)) + hours_in_minutes(days_in_hours(days,planet)) + hours_in_minutes(hours) + mins  enddef natural?(obj)    (obj.is_a?(Integer)) and (obj>=0)  end def years_in_days(years,planet)  #puts planet  years*daysPerYear(planet)enddef days_in_hours(days,planet)  days*hoursPerDay(planet)enddef hours_in_minutes(hours)  hours*minutesPerHourend#exampleputs time_in_minutes(1,1,1,1,:earth)