我通过leettime找到了twitter,这对我来说足够新颖,想要搞砸它/与你们分享。让我感到沮丧的是这个版本不会做几秒钟。似乎可能有更有效的方式来产生时间,你怎么看?
Leet Time
现在,这个leettime是如何计算的?
对于给定的人类时间(例如上午11点15分)的值 leettime对应于数字 你必须加起来13个小时 37分钟才能到达 这次。每当结果 在计算过程中溢出(即 获得的时间超过23:59 你会减去24小时 为了留在时间上。
示例:
00:00的leettime为0, 13:37的leettime是1和 leettime 2对应于03:14 am (因为13:37加13小时37 分钟是03:14。)
每个人都有一个独特的leettime 白天人性化?
是的!那里 正好是24 * 60 = 1440不同 leettimes,每个都完全对应 一天一分钟。
添加你认为很酷的其他东西,我相信这个人会喜欢它。
我把PHP版本搞定,认为它是最容易访问和便携的。 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);
}
?>
答案 0 :(得分:15)
为了更快地从HH:MM转换为Leet,请尝试使用Modular Arithmetic:
首先,将13:37转换为数字1440;具体而言,13 * 60 + 37 = 817
找到817 mod 1440的逆。结果是913(stolen from Wolfram Alpha)。 913具有913 * 817 == 1 mod 1440的属性。
或者,如果你想使用13分37秒;你会工作mod 86400,和817 ^ -1 == 67153.
将目标时间转换为数字mod 1440;然后乘以913 mod 1440得到相应的leet时间。要转换回来,乘以817。
示例:
Going from leet time to normal time (accuracy to the minute):
someLeetTime = 1337
//where 817 = 13*60 + 37 = 13:37 in minutes
timeInMinutes = someLeetTime * 817 mod 1440 = 809
hours = timeInMinutes / 60 = 13
minutes = timeInMinutes % 60 = 29
Going from normal time to leet time (accuracy to the minute):
hours = 13
minutes = 29
timeInMinutes = hours * 60 + minutes = 809
//913 = 817^-1 mod 1440
someLeetTime = timeInMinutes * 913 mod 1440 = 1337
13:29 is 1337 leet time
并且,一个可能的实施秒,13:37被视为13分37秒。 (从技术上讲违反了标准,但我们是3333,并且可以做到这一点)
Going from leet time to normal time (accuracy to the second):
someLeetTime = 1337
//where 817 = 13*60 + 37 = 13:37 in seconds
timeInSeconds = someLeetTime * 817 mod 86400 = 55529
hours = timeInSeconds / 3600 = 15
minutes = (timeInSeconds % 3600) / 60 = 25
seconds = timeInSeconds % 60 = 29
1337 in the new system is 15:25:29
Going from normal time to leet time (accuracy to the second):
hours = 15
minutes = 25
seconds = 29
timeInSeconds = hours * 3600 + minutes*60 + seconds = 55529
//67153 = 817^-1 mod 86400
someLeetTime = timeInSeconds * 67153 mod 86400 = 1337
15:25:29 is 1337 leet time
谢谢Crypto和Modular Arithmetic。
为了推动这个伟大的事业,我已经建了一个时钟! Well... 6 actually.