diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-04-07 10:33:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-07 10:33:44 +0100 |
| commit | 676a0d78e297c8da086993a25476eb497501922c (patch) | |
| tree | 770b26e7b6c82f90c7c51117d394cfd38c4dd4d9 | |
| parent | 671c9ce667ea3ce40a05cfea9ba5ea553693f496 (diff) | |
| parent | 68c3e025daa0729e8ede0637345ae3727ace8347 (diff) | |
| download | perlweeklychallenge-club-676a0d78e297c8da086993a25476eb497501922c.tar.gz perlweeklychallenge-club-676a0d78e297c8da086993a25476eb497501922c.tar.bz2 perlweeklychallenge-club-676a0d78e297c8da086993a25476eb497501922c.zip | |
Merge pull request #9882 from kjetillll/challenge-260-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-260/
| -rw-r--r-- | challenge-260/kjetillll/perl/ch-1.pl | 25 | ||||
| -rw-r--r-- | challenge-260/kjetillll/perl/ch-2.pl | 26 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-260/kjetillll/perl/ch-1.pl b/challenge-260/kjetillll/perl/ch-1.pl new file mode 100644 index 0000000000..31298d37a9 --- /dev/null +++ b/challenge-260/kjetillll/perl/ch-1.pl @@ -0,0 +1,25 @@ +use List::Util uniq; use strict; use warnings; + +sub f { + my %count; + $count{ $_ }++ for @_; + 0 + ( values %count == uniq values %count ) +} + + + +#========== Test ======================================== +use Test::More tests=>3; +is( f( @{ $$_{input} } ), $$_{output} ) for + { + input => [1,2,2,1,1,3], + output => 1 + }, + { + input => [1,2,3], + output => 0 + }, + { + input => [-2,0,1,-2,1,1,0,1,-2,9], + output => 1 + }; diff --git a/challenge-260/kjetillll/perl/ch-2.pl b/challenge-260/kjetillll/perl/ch-2.pl new file mode 100644 index 0000000000..b49f31d969 --- /dev/null +++ b/challenge-260/kjetillll/perl/ch-2.pl @@ -0,0 +1,26 @@ +use strict; use warnings; +sub permute{@_?map{my$i=$_;map[$_[$i],@$_],permute(@_[0..$i-1,$i+1..$#_])}0..$#_:[]} + +sub f { + my( $word, %n ) = shift; + $n{ $_ } //= keys %n for sort map join('',@$_), permute( split //, $word ); + $n{ $word } +} + + + +#========== Test ======================================== +use Test::More tests=>3; +is( f( $$_{input} ), $$_{output} ) for + { + input => 'CAT', + output => 3 + }, + { + input => 'GOOGLE', + output => 88 + }, + { + input => 'SECRET', + output => 255 + }; |
