aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-051/e-choroba/perl/ch-1.pl16
-rwxr-xr-xchallenge-051/e-choroba/perl/ch-2.pl27
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-051/e-choroba/perl/ch-1.pl b/challenge-051/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..282c8ddcde
--- /dev/null
+++ b/challenge-051/e-choroba/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+my @L = (-25, -10, -7, -3, 2, 4, 8, 10);
+my $target = 0;
+
+for my $i (0 .. $#L - 2) {
+ for my $j ($i + 1 .. $#L - 1) {
+ for my $k ( $j + 1 .. $#L) {
+ say join ' + ', sort { $a <=> $b } @L[$i, $j, $k]
+ if $target == $L[$i] + $L[$j] + $L[$k];
+ }
+ }
+}
diff --git a/challenge-051/e-choroba/perl/ch-2.pl b/challenge-051/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..47505bbab9
--- /dev/null
+++ b/challenge-051/e-choroba/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+use List::Util qw{ product };
+
+sub is_colorful_number {
+ my ($n) = @_;
+ my $max_length = length $n;
+ my %uniq;
+ my $count = 0;
+ for my $length (1 .. $max_length) {
+ for my $pos (0 .. $max_length - $length) {
+ my @pattern = (
+ (0) x $pos, (1) x $length, (0) x ($max_length - $pos - $length)
+ );
+ undef $uniq{
+ product((split //, $n)[ grep $pattern[$_], 0 .. $#pattern ])
+ };
+ }
+ }
+ return ($max_length ** 2 + $max_length) / 2 == keys %uniq;
+}
+
+say for grep is_colorful_number($_), 100 .. 999;
+