From: Robert Klemme Date: 2011-07-05T02:13:56+09:00 Subject: Re: Renages On Sun, Jul 3, 2011 at 11:21 AM, Peter Hicks wrote: > On Sun, 2011-07-03 at 06:12 +0900, Ryan Davis wrote: > >> It is very much a simple mapping, it just isn't a 1:1 mapping anymore. All you need to do is figure out which hour and half hour of the day it is, and return the code for that. > > John, Ryan, thank you so much - a brilliantly simple and minimal idea > that I didn't even think of. You just need to be aware that the approach works only as long as the shortest interval length is 30 minutes AND all interval endpoints are aligned with this interval length. If you need to be able to easily change any of those intervals in between you need to change the whole logic. As worst case fallback you could assume minimal resolution 1 minute and use your original input to generate an String of length 1440 (= 24 * 60, minutes per day) from it for efficient lookup. Then you have xlate[t.hour * 60 + t.min]. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/