diff options
| author | Walt Mankowski <waltman@pobox.com> | 2020-03-09 21:02:49 -0400 |
|---|---|---|
| committer | Walt Mankowski <waltman@pobox.com> | 2020-03-09 21:02:49 -0400 |
| commit | 47d0403b9274a31bb7616ea88f9ee9591f07a477 (patch) | |
| tree | 406a935435e5971f553aba1384954dfd126ef8b6 /challenge-051 | |
| parent | c12e6d9f17e4f896ba2e1690dc837327582ddef1 (diff) | |
| download | perlweeklychallenge-club-47d0403b9274a31bb7616ea88f9ee9591f07a477.tar.gz perlweeklychallenge-club-47d0403b9274a31bb7616ea88f9ee9591f07a477.tar.bz2 perlweeklychallenge-club-47d0403b9274a31bb7616ea88f9ee9591f07a477.zip | |
perl solution to problem 51-2
Diffstat (limited to 'challenge-051')
| -rw-r--r-- | challenge-051/walt-mankowski/perl/ch-2.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-051/walt-mankowski/perl/ch-2.pl b/challenge-051/walt-mankowski/perl/ch-2.pl new file mode 100644 index 0000000000..756b3c2a4c --- /dev/null +++ b/challenge-051/walt-mankowski/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use feature qw(:5.30); +use experimental qw(signatures); +use List::Util qw(product); + +# Colourful Number +# Write a script to display all Colorful Number with 3 digits. +# +# A number can be declare Colorful Number where all the products of +# consecutive subsets of digit are different. +# +# For example, 263 is a Colorful Number since 2, 6, 3, 2x6, 6x3, 2x6x3 are unique. + +sub is_colorful($n) { + my %prods; + for my $len (1..length($n)) { + for my $i (0..length($n) - $len) { + my $p = product split //, substr($n, $i, $len); + if (defined $prods{$p}) { + return 0; + } else { + $prods{$p} = 1; + } + } + } + return 1; +} + +for my $n (100..999) { + say $n if is_colorful($n); +} |
