diff options
| -rwxr-xr-x | challenge-277/alexander-karelas/perl/ch-1.pl | 13 | ||||
| -rwxr-xr-x | challenge-277/alexander-karelas/perl/ch-2.pl | 23 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-277/alexander-karelas/perl/ch-1.pl b/challenge-277/alexander-karelas/perl/ch-1.pl new file mode 100755 index 0000000000..c3f05073f2 --- /dev/null +++ b/challenge-277/alexander-karelas/perl/ch-1.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl + +use v5.40; + +my @words1 = ("Perl", "is", "my", "friend"); +my @words2 = ("Perl", "and", "Raku", "are", "friend"); + +# Solution: +my %hash; +@hash{ @words1 } = (); +my $num_common = grep exists $hash{$_}, @words2; + +say $num_common; diff --git a/challenge-277/alexander-karelas/perl/ch-2.pl b/challenge-277/alexander-karelas/perl/ch-2.pl new file mode 100755 index 0000000000..be524997a2 --- /dev/null +++ b/challenge-277/alexander-karelas/perl/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use v5.40; + +use List::Util 'min'; + +my @ints = (1, 2, 3, 4, 5); + +# Solution +sub is_strong ($x, $y) { + return 0 < abs($x - $y) < min($x, $y); +} + +my @strong_pair_strings; +for my $j (1 .. $#ints) { + my $y = $ints[$j]; + for my $i (0 .. $j-1) { + my $x = $ints[$i]; + push @strong_pair_strings, "($x, $y)" if is_strong($x, $y); + } +} + +say "Strong pairs: ", join ', ', @strong_pair_strings;
\ No newline at end of file |
