in reply to Generic De Bruijn Sequence

You wanted tweaks :) This is at least smaller.

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1188292 use strict; use warnings; my $n = shift // 3; # alphabet size my $t = shift // $n; # size of tuples my @alphabet = ('A'..'Z', '0'..'9', 'a'..'z'); my (%next, %all); @next{'', @alphabet} = @alphabet; $_ = $alphabet[0] x $t; # start of string my $over = $alphabet[$n]; # outside of alphabet my $need = $n ** $t + $t - 1; 1 while s/^(?=(.{$t})) (?=.+\1) (.) | $over(.)/$next{$+}/x # advance c +har or s/^ (?=.{$t}) (?!.{$need}) /$alphabet[0]/x; # add new char print; # then prove it is correct $all{$1}++ while /(?=(.{$t}))/g; print "want @{[ $n ** $t ]} unique tuples, have @{[ scalar keys %all ] +}";