Skip to content

Instantly share code, notes, and snippets.

@bolechen
Last active October 27, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bolechen/1e4436ee8516cddd82fca8e1eed41d0c to your computer and use it in GitHub Desktop.
Save bolechen/1e4436ee8516cddd82fca8e1eed41d0c to your computer and use it in GitHub Desktop.
男人袜十周年 iPhone12 抽奖算法
<?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