diff options
Diffstat (limited to 'challenge-107/pete-houston/perl/ch-1.pl')
| -rw-r--r-- | challenge-107/pete-houston/perl/ch-1.pl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-107/pete-houston/perl/ch-1.pl b/challenge-107/pete-houston/perl/ch-1.pl new file mode 100644 index 0000000000..d10e4a68b8 --- /dev/null +++ b/challenge-107/pete-houston/perl/ch-1.pl @@ -0,0 +1,38 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: 10701.pl +# +# USAGE: ./10701.pl +# +# DESCRIPTION: Outputs the first 3 self-descriptive numbers +# +# REQUIREMENTS: Perl 5.10, List::Util +# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk +# ORGANIZATION: Openstrike +# VERSION: 1.0 +# CREATED: 06/04/21 +#=============================================================================== + +use strict; +use warnings; +use 5.010; +use List::Util 'sum'; + +my $x = 0; +my @sdn; +my %cinit = map { $_ => 0 } 0 .. 9; + +OUTER: while ($#sdn < 2) { + $x++; + my @digits = split //, $x; + next unless @digits == sum (@digits); + my %count = %cinit; + $count{$_}++ for @digits; + for my $i (0 .. $#digits) { + next OUTER unless $count{$i} == $digits[$i]; + } + push @sdn, $x; +} + +print join (', ', @sdn), "\n"; |
