Created
February 6, 2024 12:53
-
-
Save rudiedirkx/251ad28695ba6821ed7e816d6bd94ce4 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 | |
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