in reply to Re^2: Algorithm RFC: fast (pseudo-)random shuffle with no repetition
in thread Algorithm RFC: fast (pseudo-)random shuffle with no repetition
It seems like that is actually a bit unwieldy. Another try:
#!/usr/bin/env perl use strict; use warnings; use Algorithm::Permute; use Data::Dump; use List::Util qw(shuffle); use feature qw(say); my @n = shuffle( 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 11, 12, 13, + 14, 14, 15 ); my $p = Algorithm::Permute->new( \@n, 20 ); my $m3 = qr/(.)\1\1/; my $m2 = qr/(.)\1/; PERMUTE: { my @r = $p->next; dd \@r; my $s = pack( "(A*)*", @r ); if ( $s =~ /($m3)/ ) { # say $1; # sleep 1; goto PERMUTE; } if ( $s =~ /($m2)/ ) { # say $1; # sleep 1; goto PERMUTE; } say join " ", @r; } __END__
Minor update: Fixed dead code.
«The Crux of the Biscuit is the Apostrophe»
|
---|