8 chomp (my @rules = <>);
13 if (/swap position (\d+) with position (\d+)/) {
14 (substr($data, $1, 1), substr($data, $2, 1))
15 = (substr($data, $2, 1), substr($data, $1, 1));
16 } elsif (/swap letter (\w) with letter (\w)/) {
17 eval "\$data =~ y/$1$2/$2$1/";
18 } elsif (/rotate left (\d+) /) {
20 $data =~ s/^(.{$n})(.*)/$2$1/;
21 } elsif (/rotate right (\d+) /) {
23 $data =~ s/^(.*)(.{$n})/$2$1/;
24 } elsif (/rotate based on position of letter (\w)/) {
26 my ($pref) = $data =~ /^(.*$l)/;
27 my $pos = length($pref);
29 $pos -= length($data) if $pos >= length($data);
30 $data =~ s/^(.*)(.{$pos})/$2$1/ if $pos;
31 } elsif (/reverse positions (\d+) through (\d+)/) {
32 substr($data, $1, $2-$1+1) = join('', reverse split //,
33 substr($data, $1, $2-$1+1));
34 } elsif (/move position (\d+) to position (\d+)/) {
35 my $l = substr($data, $1, 1);
36 substr($data, $1, 1) = '';
37 substr($data, $2, 0) = $l;
39 die "Unknown command $_.";
46 my ($pass, @rest) = @_;
48 if (scramble($pass) eq 'fbgdceah') {
53 for my $i (0 .. $#rest) {
55 my $c = splice (@nr, $i, 1);
60 perm('', split //, 'abcdefgh');