Created
June 4, 2013 04:28
-
-
Save dexterbt1/5703574 to your computer and use it in GitHub Desktop.
Generate a sequence of unique characters e.g. 3333, 3334 ... YYYX, YYYY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
my $chars_str = '3456789ABCDEFGHJKMNPRSTUVWXY'; | |
my @chars = split //, $chars_str; | |
# a b c d | |
my $template = [ 0, 0, 0, 0, 0 ]; | |
my $dead_end = 0; | |
while (1) { | |
print join('', map { $chars[$_] } @$template),"\n"; | |
my $ti = scalar(@$template)-1; | |
if ($template->[$ti] < scalar(@chars)-1) { | |
$template->[$ti]++; | |
} | |
else { | |
while (1) { | |
$ti--; | |
if ($template->[$ti] < scalar(@chars)-1) { | |
$template->[$ti]++; | |
for ($ti+1 .. scalar(@$template)-1) { | |
$template->[$_] = 0; | |
} | |
last; | |
} | |
if ($ti < 0) { | |
$dead_end = 1; | |
last; | |
} | |
} | |
} | |
last if ($dead_end); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment