in reply to random pairs
Update: Added test for both elements being equal.use Modern::Perl; my %test; my @predetermined; my @results; push @predetermined, int(rand(100)) for 1 .. 100; for my $element (@predetermined) { my $pair; { $pair = int(rand(100)); redo if $test{$element.'-'.$pair} or $test{$pair.'-'.$element} + or $pair == $element; } $test{$element.'-'.$pair} = $test{$pair.'-'.$element} = 1; push @results, $element.'-'.$pair; } say for sort(@results);
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: random pairs
by Anonymous Monk on Jul 16, 2012 at 20:00 UTC | |
by CountZero (Bishop) on Jul 16, 2012 at 22:30 UTC | |
by Anonymous Monk on Jul 19, 2012 at 16:43 UTC | |
by CountZero (Bishop) on Jul 19, 2012 at 19:41 UTC |