diff options
| author | Kjetil Skotheim <kjetil.skotheim@sikt.no> | 2024-04-07 00:39:20 +0200 |
|---|---|---|
| committer | Kjetil Skotheim <kjetil.skotheim@sikt.no> | 2024-04-07 00:39:20 +0200 |
| commit | 68c3e025daa0729e8ede0637345ae3727ace8347 (patch) | |
| tree | aad010da18339a918a7b2f927c6884d704682f7c | |
| parent | 5e7b7cfa1f272e562842627843bc71ae40d79260 (diff) | |
| download | perlweeklychallenge-club-68c3e025daa0729e8ede0637345ae3727ace8347.tar.gz perlweeklychallenge-club-68c3e025daa0729e8ede0637345ae3727ace8347.tar.bz2 perlweeklychallenge-club-68c3e025daa0729e8ede0637345ae3727ace8347.zip | |
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 + }; |
