#!/usr/bin/perl -w use strict; my @set = (1 .. 9); my %point; my ($x, $y); # something for the last element left to point to my $last = $set[-1]; # prime the pump $x = pop @set; while (@set) { # grab something that's left $y = splice @set, ((rand @set) - 1), 1; $point{$x} = $y; # do that one next $x = $y; } # take care of that straggler $point{$x} = $last; # and now a demo foreach my $key (keys %point) { print "$key points to ", $point{$key}, "\n"; }
In reply to RE: Swap-a-roo
by chromatic
in thread Swap-a-roo
by turnstep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |