From: Ryan Davis Date: 2011-07-06T05:52:18+09:00 Subject: Re: Renages On Jul 5, 2011, at 10:34 , Rob Biedenharn wrote: > You just need to check from the "end" on back and pick the first one that matches. > > xlate = [ [ '0000', '0' ], [ '0100', '1' ], [ '0200', '2' ], [ '0300', '3' ], > [ '0400', '4' ], [ '0500', '5' ], [ '0600', '6' ], [ '0700', 'A' ], > [ '0730', 'B' ], [ '0800', 'C' ], [ '0830', 'D' ], [ '0900', 'E' ], > [ '0930', 'F' ], [ '1000', 'G' ], [ '1030', 'H' ], [ '1100', 'I' ], > [ '1130', 'J' ], [ '1200', 'K' ], [ '1230', 'L' ], [ '1300', 'M' ], > [ '1330', 'N' ], [ '1400', 'O' ], [ '1430', 'P' ], [ '1500', 'Q' ], > [ '1530', 'R' ], [ '1600', 'S' ], [ '1630', 'T' ], [ '1700', 'U' ], > [ '1730', 'V' ], [ '1800', 'W' ], [ '1830', 'X' ], [ '1900', 'Y' ], > [ '2000', 'Z' ], [ '2100', '7' ], [ '2200', '8' ], [ '2300', '9' ], > ].reverse > # Note the .reverse here > > time = Time.now.strftime('%H%M') > xlate.detect{|(start,code)| time >= start} simple benchmark: real math 1.180000 0.000000 1.180000 ( 1.193925) table lookup 13.460000 0.040000 13.500000 ( 14.111571)