我通过推特发现了leettime,它的新颖性足以让我想要搞砸它/与你们分享.让我感到沮丧的是这个版本不会做几秒钟.似乎可能有更有效的方式来产生时间,你怎么看?
Leet时间
现在,这个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版本搞定,认为它是最容易访问和便携的.其他版本可在此处获得.
<?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);
}
?>
Run Code Online (Sandbox Code Playgroud)
Cod*_*Tao 15
要快速从HH:MM转换为Leet,请尝试使用Modular Arithmetic:
首先,将13:37转换为数字mod 1440; 具体而言,13*60 + 37 = 817
找到817 mod 1440的倒数.结果是913(从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
Run Code Online (Sandbox Code Playgroud)
并且,一个可能的实施秒,在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
Run Code Online (Sandbox Code Playgroud)
谢谢Crypto和Modular Arithmetic.
为了推动这个伟大的事业,我建造了一个时钟! 嗯......实际上是6.