diff options
| -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 + }; |
