Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Unlike the others this is untested.

    my @votes = do {
        my $votes = open($votes_file);
        =$votes
    };

    my $count = 0;
    my %skip;

    loop {
        say "\nRound {++$count}";

        my @ranking = CountRound( @votes, %skip ).pairs.sort({.value});

        say sprintf "%s: %s", .key, .value
            for @ranking;

        given @ranking[0].value {
            when $_ > 0.5 {
                say sprintf "\nThe winner is %s with %.0f%% of the vote.", .key, .value;
                exit;
            }
        }

        my $skip = @ranking[-1].key;
        %skip{ $skip } = 1;
        say "Skipping $skip";
    }

    • That CountRound line is nice. I've worked it into my code, I'll post another full version as a fresh post. Thanks!