- or download this
sub canonical {
my(@a,$i,%c,$c)=pop=~/./g;$c.=$c{$_}||=$a[$i++]for pop=~/./g;$c
}
- or download this
sub canonical {
($_,$a,%h)=@_;s!.!$h{$&}||=($a=~/./g,$&)!ge;$_
}
- or download this
sub canonical {
($_,$a,%h)=@_;s!.!{$h{$&}=~s+^\z+$a=~/./gs,$&+ge}$h{$&}!gse;$_
}