in reply to Lottery combinations golf
Well, I had thought that perhaps Algorithm::Permute might be the answer, but according to its documentation, so far it only deals with n arrangements of n items. Given that, and the amount of time it can take for even a small set of matches, I tossed together the following, based fairly closely on its docs. I *DO NOT* recommend this method (because it is highly inefficient, in just about every way I can think of).
#!/usr/bin/perl -w use strict; use Algorithm::Permute; $| = 1; my @spinner = ('|', '/', '-', '\\'); my $bigscale = 100_000; my $scale = 100; my $index = 0; my $draw_max = 9; my $draw_min = 1; my $to_draw = 6; my (%seen); my (@res); my $p = new Algorithm::Permute([$draw_min .. $draw_max]); while (@res = $p->next) { my $st = join(', ', sort(@res[0 .. ($to_draw - 1)])); $seen{$st} = 1; print $spinner[($index++ / $scale) % 4], "\b"; print '.' unless ($index % $bigscale); } print join "\n", sort keys %seen;
|
|---|