From 3e191377825ad831a11e6465dc80e378c28c8848 Mon Sep 17 00:00:00 2001 From: rage311 Date: Sun, 17 Oct 2021 15:38:07 -0600 Subject: Added ch-1 --- challenge-134/rage311/perl/ch-1.pl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-134/rage311/perl/ch-1.pl diff --git a/challenge-134/rage311/perl/ch-1.pl b/challenge-134/rage311/perl/ch-1.pl new file mode 100644 index 0000000000..d53ac7230f --- /dev/null +++ b/challenge-134/rage311/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use 5.034; +use warnings; +use feature 'signatures'; +no warnings 'experimental::signatures'; + +sub pandigital ($base, $count) { + return if $count < 1; + my $prev = + ( + ($base ** $base - $base) + / ($base - 1) ** 2 + ) + + ($base - 1) + * ($base ** ($base - 2)) + - 1; + + my @results = $prev; + + while (@results < $count) { + my %digits; + my @chars = split //, ++$prev; + $digits{$_} = 1 for @chars; + next unless keys %digits == $base; + push @results, join '', @chars; + } + + return @results; +} + +say for pandigital(10, 10); -- cgit