I found leettime via twitter, and it's novel enough for me to want to mess around with it/share it with you guys. To my dismay this version doesn't do seconds. It also seems like there might be a more efficient way to generate the time, what do you think?
Leet Time
Now, how is this leettime calculated?
For a given humantime (e.g. 11:15 am) the value of the leettime corresponds to the number of times you have to add up 13 hours 37 minutes in order to exactly reach this time. Whenever the result overflows during the calculation (i.e. the obtained time exceeds 23:59 o'clock) you subtract 24 hours in order to stay on the clock.
Example:
The leettime of 00:00 is 0, the leettime of 13:37 is 1 and leettime 2 corresponds to 03:14 am (because 13:37 plus 13 hours 37 minutes is 03:14 o'clock).
Is there a unique leettime for every humantime during the day?
Yes! There are exactly 24*60=1440 different leettimes, each corresponds to exactly one minute in the day.
Add whatever else you think would be cool, I'm sure this guy would love it.
I put the PHP version up figuring it'd be the most accessible and portable. The other versions are available here.
<?php
/**
* Converts standard time to leettime.
*
* @param int h the hour in standard time
* @param int m the minute in standard time
*
* @return int the leettime or -1 if the input
* parameters are invalid
*/
function TimeToLeet($h, $m){
if(!is_numeric($h) || !is_numeric($m) ||
$h > 23 || $h < 0 || $m > 59 || $m < 0)
return -1;
$curm = 0;
$curh = 0;
$i = 0;
while ($curm != $m || ($curh % 24) != $h){
if($curm < 23){
$curh += 13;
$curm += 37;
} else {
$curh += 14;
$curm -= 23;
}
++$i;
}
return $i;
}
/**
* Converts leettime to standard time.
*
* @param int leet the time in leettime-format in the
* range from 0 - 1439
*
* @return var an int-Array with the hours at position 0
* and minutes at position 1 (-1 if the input parameter
* is not in range)
*/
function LeetToTime($leet){
if($leet > 1439 || $leet < 0) return array(-1, -1);
$m = $leet * 37;
$h = ($leet * 13) + ($m / 60);
return array($h % 24, $m % 60);
}
// Demonstrate usage
$h = (int)date("G");
$m = (int)date("i");
echo date("H:i")." = ".TimeToLeet($h,$m);
echo "
";
$leettime = 999;
$result = LeetToTime($leettime);
if($result[0] == -1) echo "error";
else {
$h = $result[0];
$m = $result[1];
echo $leettime." = ".($h>9?$h:"0".$h) .
":".($m>9?$m:"0".$m);
}
?>