Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Created February 6, 2024 12:53
Show Gist options
  • Select an option

  • Save rudiedirkx/251ad28695ba6821ed7e816d6bd94ce4 to your computer and use it in GitHub Desktop.

Select an option

Save rudiedirkx/251ad28695ba6821ed7e816d6bd94ce4 to your computer and use it in GitHub Desktop.

Revisions

  1. rudiedirkx created this gist Feb 6, 2024.
    19 changes: 19 additions & 0 deletions votes.php
    Original 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";
    }