Last active
October 27, 2020 08:04
男人袜十周年 iPhone12 抽奖算法
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 | |
/** | |
* 男人袜十周年活动. | |
* 抽奖规则说明:11.25 收盘时的上证指数 × 深证成指 × 10000 = 12 位数(指数以活动页面公布链接数字为准); | |
* 将此 12 位数的数字倒序排列后,再除以本次活动结束时的参与人次(每个抽奖号为一个人次),得到的余数加 1 即为获奖号码。 | |
* | |
* @param float $sh 上证指盘收盘价 | |
* @param float $sz 深证成指收盘价 | |
* @param int $totalCount 参与人次(每个抽奖号为一个人次) | |
* | |
* @return int 中奖编号 | |
*/ | |
function whoGetiPhone12(float $sh, float $sz, int $totalCount): int | |
{ | |
$rand = strrev(strval($sh * $sz * 10000)); | |
return ($rand % $totalCount) + 1; | |
} | |
if (isset($argv[1], $argv[2], $argv[3])) { | |
printf('中奖编号为: %d', whoGetiPhone12($argv[1], $argv[2], $argv[3])); | |
} else { | |
echo '使用方法 `php iPhone12.php 上证指数 深证成数 参与人次`'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment