Public feed #376512

Permutations

public text v1 · immutable
Raw Edit
·published 2007-03-01 02:20 UTC
rendered paste body
#! /usr/bin/perl
use strict;
use warnings qw(all);
sub permute {
 @_ = ("",@_) if 1 == scalar @_;
 my ($string,$arg) = @_;
 my @todo = @$arg;
 unless(@todo){ print "$string\n"; return; }

 my @done;
 while(@todo){
     my $val = shift @todo;
     my $sv = $string . $val;
         my $array = [@todo,@done];
     permute($string . $val, $array);
     push @done, $val;
     }
 }

permute(["1","2","3","4","5","q","x"]);