Created
February 6, 2024 12:53
-
-
Save rudiedirkx/251ad28695ba6821ed7e816d6bd94ce4 to your computer and use it in GitHub Desktop.
Revisions
-
rudiedirkx created this gist
Feb 6, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <?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"; }