# Perl 6, 117 bytes say $_ <2??1!!permutations(+[(my@n=(^$_).join.comb)]).elems÷[*] ([*] 2..$_ for @n.classify(&unique).values)for lines and in a more readable fasion for (lines) -> $number { say 1 and next if $number < 2; my @digits = (^$number).join.comb; my @duplicates = @digits.classify(&unique).values; my $unique_permutations = permutations(+@digits).elems ÷ [*] ([*] 2..$_ for @duplicates); say $unique_permutations; }