Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Last active May 28, 2020 10:50
Show Gist options
  • Save PJZ9n/d3d947c537bb33d9176a368e01d26a6e to your computer and use it in GitHub Desktop.
Save PJZ9n/d3d947c537bb33d9176a368e01d26a6e to your computer and use it in GitHub Desktop.
確率からn/65536のnを求める
<?php
declare(strict_types=1);
function get(string $per, ?int $keta = null)
{
if ($keta === null) {
preg_match('/\.[0-9]+/', $per, $matches);
$m = $matches[0];
$keta = strlen($m) - 1;
}
echo "Check for $per, Keta $keta" . PHP_EOL;
$hits = 0;
for ($i = 1; $i <= 65536; $i++) {
$h = strval(65536 / $i);
if ($h === $per || strpos($h, $per) === 0) {
echo "Hit: $i, Per: $per, H: $h, P: " . (65536 / $i) . ", G: " . round(65536 / $i, $keta) . PHP_EOL;
$hits++;
}
}
if ($hits <= 0) {
echo "NO HIT" . PHP_EOL;
}
}
get("6.180");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment