diff options
| author | Alexander Karelas <karjala@cpan.org> | 2024-07-08 13:43:26 +0000 |
|---|---|---|
| committer | Alexander Karelas <karjala@cpan.org> | 2024-07-08 13:43:26 +0000 |
| commit | a9991a8d5d08fcc9f158174343a7308e75122c0e (patch) | |
| tree | e6bd4697aafc9c499d963c09eeab7642ce99895a | |
| parent | 4fefb9a739b7cf52eaa21886032dbb869db63c13 (diff) | |
| download | perlweeklychallenge-club-a9991a8d5d08fcc9f158174343a7308e75122c0e.tar.gz perlweeklychallenge-club-a9991a8d5d08fcc9f158174343a7308e75122c0e.tar.bz2 perlweeklychallenge-club-a9991a8d5d08fcc9f158174343a7308e75122c0e.zip | |
alexander karelas's solutions
| -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 |
