Created
March 30, 2014 01:24
-
-
Save dvl/9865794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _hot($upvotes = 0, $downvotes = 0, $posted = 0) { | |
$s = $upvotes - $downvotes; | |
$order = log(max(abs($s), 1), 10); | |
if ($s > 0) { | |
$sign = 1; | |
} | |
elseif($s < 0) { | |
$sign = -1; | |
} | |
else { | |
$sign = 0; | |
} | |
$seconds = $posted - 1134028003; | |
return round($sign * $order + (int)($seconds / 45000), 7); | |
} | |
echo _hot(1000, 1500, 1262304000) . PHP_EOL; // 2847.30103 | |
echo _hot(1000, 1500, 1353107345) . PHP_EOL; // 4865.30103 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from __future__ import division # uncomment for same PHP's behaviour | |
from math import log10 | |
def score(n1, n2): | |
return n1 - n2 | |
def _hot(ups, downs, date): | |
s = score(ups, downs) | |
order = log10(max(abs(s), 1)) | |
if s > 0: | |
sign = 1 | |
elif s < 0: | |
sign = -1 | |
else: | |
sign = 0 | |
seconds = date - 1134028003 | |
return round(sign * order + seconds / 45000, 7) | |
print _hot(1000, 1500, 1262304000) # py3 2847.8787411, py2 2847.30103 | |
print _hot(1000, 1500, 1353107345) # py3 4865.7308522, py2 4865.30103 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo intval(3.3) . PHP_EOL; // 3 | |
echo intval(3.5) . PHP_EOL; // 3 | |
echo intval(3.9) . PHP_EOL; // 3 | |
echo round(3.3) . PHP_EOL; // 3 | |
echo round(3.5) . PHP_EOL; // 4 | |
echo round(3.9) . PHP_EOL; // 4 | |
echo floor(3.3) . PHP_EOL; // 3 | |
echo floor(3.5) . PHP_EOL; // 3 | |
echo floor(3.9) . PHP_EOL; // 3 | |
echo (int) 3.3 . PHP_EOL; // 3 | |
echo (int) 3.5 . PHP_EOL; // 3 | |
echo (int) 3.9 . PHP_EOL; // 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print int(3.3) # 3 | |
print int(3.5) # 3 | |
print int(3.9) # 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment