diff options
| author | Steven <steven1170@zoho.eu> | 2025-02-11 16:31:46 +0000 |
|---|---|---|
| committer | Steven <steven1170@zoho.eu> | 2025-02-11 16:31:46 +0000 |
| commit | 4e45c44c570fd4a77a5a76236bb763d4d9b859ec (patch) | |
| tree | 5b2a0e575b148d21c3512a6344e0afe933652301 /challenge-308/steven-wilson/perl/ch-1.pl | |
| parent | d8179c22c12d35d4201bc8e3f759a4a8009e6b1b (diff) | |
| download | perlweeklychallenge-club-4e45c44c570fd4a77a5a76236bb763d4d9b859ec.tar.gz perlweeklychallenge-club-4e45c44c570fd4a77a5a76236bb763d4d9b859ec.tar.bz2 perlweeklychallenge-club-4e45c44c570fd4a77a5a76236bb763d4d9b859ec.zip | |
add solutions week 308 in python & perl
Diffstat (limited to 'challenge-308/steven-wilson/perl/ch-1.pl')
| -rw-r--r-- | challenge-308/steven-wilson/perl/ch-1.pl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-308/steven-wilson/perl/ch-1.pl b/challenge-308/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..76bbb72e2f --- /dev/null +++ b/challenge-308/steven-wilson/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +use v5.35; +use Test2::Bundle::More; + +sub countCommon{ + my ($ref1, $ref2) = @_; + my %strings1; + $strings1{$_}++ for (@$ref1); + my %strings2; + $strings2{$_}++ for (@$ref2); + my @intersection = grep { exists $strings1{$_} } keys %strings2; + return scalar @intersection; +} + +my @str1 = ("perl", "weekly", "challenge"); +my @str2 = ("raku", "weekly", "challenge"); +is(countCommon(\@str1, \@str2), 2, "Test 1"); + +my @str3 = ("perl", "raku", "python"); +my @str4 = ("python", "java"); +is(countCommon(\@str3, \@str4), 1, "Test 2"); + +my @str5 = ("guest", "contribution"); +my @str6 = ("fun", "weekly", "challenge"); +is(countCommon(\@str5, \@str6), 0, "Test 3"); + +done_testing(); |
