in reply to how to add a counter

The formula to get the total number of all possible combinations can be found at Wikipedia if you do not remember it. Then just increase a counter for each combination and print the ratio:
#!/usr/bin/perl use warnings; use strict; use Algorithm::Combinatorics qw(combinations); my $rep = 10; my @data = 1 .. $rep; my $size = 4; my $iter = combinations(\@data, $size); my $maxcount = 1; $maxcount *= $_ for 1 + $rep - $size .. $rep; $maxcount /= $_ for 2 .. $size; my $count = 1; while (my ($w, $x, $y, $z) = @{ $iter->next // [] }) { $count++; next unless $w-2*$x+$y or $x-2*$y+$z; print $count/$maxcount, "\t$w, $x, $y, $z\n"; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: how to add a counter
by crunch_this! (Acolyte) on May 30, 2013 at 03:24 UTC
    That's great, I wouldn't have thought of all that but I can take it from there. I don't know why I got down-voted, maybe it was because I didn't credit hdb like maybe I should have (which I fixed).