Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created August 25, 2010 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugyan/550023 to your computer and use it in GitHub Desktop.
Save sugyan/550023 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/activeperl
use strict;
use warnings;
use List::Util 'shuffle';
my @char = qw/( ) { } [ ] . ^ ? ~ !/;
my $dict;
for my $a (shuffle @char) {
for my $b (shuffle @char) {
for my $c (shuffle @char) {
for my $d (shuffle @char) {
push @{$dict->{$a^$b^$c^$d}}, [$a, $b, $c, $d];
}
}
}
}
my @str;
for (split //, 'map eval q#$a=1;map$a*=$_,1..$_;print"$_! = $a\n"#, 1..$ARGV[0]||1') {
my @arr = shuffle @{ (map $_->[0], sort { $b->[1] <=> $a->[1] } map { [$_, scalar(my @a = join('', @$_)=~/[(){}]/g)] } @{ $dict->{$_} })[0] };
for (0..3) {
$str[$_] .= $arr[$_];
}
}
print q/''!~('(?{'.('/ . join(q/'^'/, @str) . q/').'})')/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment