Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Created February 6, 2024 12:53
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 rudiedirkx/251ad28695ba6821ed7e816d6bd94ce4 to your computer and use it in GitHub Desktop.
Save rudiedirkx/251ad28695ba6821ed7e816d6bd94ce4 to your computer and use it in GitHub Desktop.
<?php
totalVotes(18.7);
totalVotes(14.3);
totalVotes(45.5);
function totalVotes(float $target, float $margin = 0.08) : void {
echo "$target %...\n";
$fVotes = 100 / $target;
echo "~ $fVotes votes...\n";
for ($i = 1; $i < 50; $i++) {
$votes = $i * $fVotes;
if (abs($votes - round($votes)) < $margin) {
$total = round($votes);
echo "= $i / $total = " . ($i / $total * 100) . "\n";
}
}
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment