require 'rubygems'
require 'activesupport'
h={}
j=24*60
d=Date.parse('2009-01-01 00:00')
# increment time by 13 hours, 37 minutes
# and store leettime value in the hash
j.times do |i|
h[(d+(i*13).hours+(i*37).minutes).strftime('%H:%M')]=i
end
# output leettime for all humantimes from 00:00 to 23:59
h.keys.sort.each do |k|
puts "#{k} #{h[k]}"
end
<?php
$h=(int)date("G");
$m=(int)date("i");
$curm=0;
$curh=0;
$i=0;
while ($curh != $h || $curm != $m){
$curh+=13;
$curm+=37;
if($curm>59){
$curm-=60;
$curh+=1;
}
if($curh>23){
$curh-=24;
}
++$i;
}
echo date("H:i")." = ".$i;
?>
<?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);
}
?>
import java.util.Calendar;
/**
* A class to convert between leettime and standard time
*/
public class leettime{
/**
* The main method to demonstrate the usage of this
* class.
*
* @param args the command line arguments
* @throws Exception
*/
public static void main(String[] args)
throws Exception {
leettime leet = new leettime();
int h = Calendar.getInstance().get(
Calendar.HOUR_OF_DAY);
int m = Calendar.getInstance().get(Calendar.MINUTE);
System.out.println(
(h>9?h:"0"+h) + ":" + (m>9?m:"0"+m) + " = " +
leet.TimeToLeet(h,m)
);
int leettime = 999;
int[] result = leet.LeetToTime(leettime);
if(result[0] == -1) System.out.println("error");
else {
h = result[0];
m = result[1];
System.out.println(
leettime + " = " + (h>9?h:"0"+h) + ":" +
(m>9?m:"0"+m)
);
}
}
/**
* Converts standard time to leettime.
*
* @param h the hour in standard time
* @param m the minute in standard time
*
* @return the leettime or -1 if the input
* parameters are invalid
*/
public int TimeToLeet(final int h, final int m){
if(h > 23 || h < 0 || m > 59 || m < 0) return -1;
int curm = 0;
int curh = 0;
int 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 leet the time in leettime-format in the range
* from 0 - 1439
*
* @return an int-Array with the hours at position 0
* and minutes at position 1 (-1 if the input
* parameter is not in range)
*/
public int[] LeetToTime(final int leet){
if(leet > 1439 || leet < 0){
int[] result = {-1, -1};
return result;
}
int m = leet * 37;
int h = (leet * 13) + (m / 60);
int[] result = {h % 24 , m % 60};
return result;
}
}
Leetime in other languages
We will happily post your implementations here. Feel
free to use the language of choice!