32:my $only_unique = 1; # eliminate numbers that are just a reordering of digits
43: ## we store only unique "constellations" of digits by sorting and using the
44: ## hash to remove duplicates. we also must sort the value it points to.
45: if ($only_unique) {$n = sortHiLow($n);
46: $nn = sortHiLow($nn);}
####
100:## runs kaprekar routine on a number until it either cycles or converges:
101:sub kRoutine {
####
72:## given a number, performs one iteration of the kaprekar routine and returns num
73:sub gotoNext {
74: my $n = shift;
75: my $new_num = sortHiLow($n) - sortLowHi($n);
76: while (length $new_num < $digits)
77: {$new_num = ("0" . "$new_num")}
78:
79: return $new_num;
80:}
####
sub gotoNext {
my $n = shift;
sprintf '%0*d', $digits, sortHiLow( $n ) - sortLowHi( $n );
}