Skip to content

Instantly share code, notes, and snippets.

@dexterbt1
Created June 4, 2013 04:28
Show Gist options
  • Save dexterbt1/5703574 to your computer and use it in GitHub Desktop.
Save dexterbt1/5703574 to your computer and use it in GitHub Desktop.
Generate a sequence of unique characters e.g. 3333, 3334 ... YYYX, YYYY
#!/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