aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-02-13 14:46:13 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-02-13 14:46:13 +0000
commit034057dcb7b2a08bee0a408726121320c1355fb2 (patch)
tree50c0b4b6d21141aa5a436539f51c7faaaadda273
parent3957a4fbac71408ac235fff57696f9bf84eea053 (diff)
downloadperlweeklychallenge-club-034057dcb7b2a08bee0a408726121320c1355fb2.tar.gz
perlweeklychallenge-club-034057dcb7b2a08bee0a408726121320c1355fb2.tar.bz2
perlweeklychallenge-club-034057dcb7b2a08bee0a408726121320c1355fb2.zip
golfed even further
-rw-r--r--challenge-097/james-smith/perl/ch-2.pl22
1 files changed, 12 insertions, 10 deletions
diff --git a/challenge-097/james-smith/perl/ch-2.pl b/challenge-097/james-smith/perl/ch-2.pl
index 42e29e5a59..881a3a24b0 100644
--- a/challenge-097/james-smith/perl/ch-2.pl
+++ b/challenge-097/james-smith/perl/ch-2.pl
@@ -34,12 +34,12 @@ is( mf_3('101100100100101',3), 2 );
is( mf_3('101101',3), 0 );
is( mf_3('0000000100100011010001010110011110001001101010111100110111101111',4), 32 );
-is( mf_g('101100101',3), 1 );
-is( mf_g('10110111', 4), 2 );
-is( mf_g('100101100',3), 1 );
-is( mf_g('101100100100101',3), 2 );
-is( mf_g('101101',3), 0 );
-is( mf_g('0000000100100011010001010110011110001001101010111100110111101111',4), 32 );
+is( mf('101100101',3), 1 );
+is( mf('10110111', 4), 2 );
+is( mf('100101100',3), 1 );
+is( mf('101100100100101',3), 2 );
+is( mf('101101',3), 0 );
+is( mf('0000000100100011010001010110011110001001101010111100110111101111',4), 32 );
is( min_flips_more_readable('101100101',3), 1 );
is( min_flips_more_readable('10110111', 4), 2 );
@@ -152,11 +152,13 @@ sub mf_1{[local$/=length$_[0],local$\=$//$_[1],map{$/=$_<$/?$_:$/}map{($_[0]^$_)
sub mf_2{[local$/=length$_[0],local$\=$//$_[1],map{$/=$_<$/?$_:$/}map{($_[0]^$_)
=~y/\1/\1/}map{$_ x$\}map{substr$_[0],$_,$_[1]}map{$_*$_[1]}0..$\-1]->[-1]}
-## Golf extra (less readable!) [at 125 characters] - 115 inside the curly braces..
+## Golf extra (less readable!) [at 112 characters] - 104 inside the curly braces..
## but side effects as no longer localise $/ & $\
-sub mf_g{[$/=length$_[0],$\=$//$_[1],map{$/=$_<$/?$_:$/}map{
-($_[0]^substr($_[0],$_*$_[1],$_[1])x$\)=~y/\1/\1/}0..$\-1]->
-[-1]}
+## Note as $a/$b are used in sort - you don't need to my them even though we are using strict...
+
+sub mf{(($a,$b)=@_,$/=length$a,$\=$//$b,
+map{$/=$_<$/?$_:$/}map{($a^substr($a,$_*
+$b,$b)x$\)=~y/\1//}0..$\-1)[-1]}
sub mf_3{[local$/=length$_[0],local$\=$//$_[1],map{$/=$_<$/?
$_:$/}map{($_[0]^$_)=~y/\1/\1/}map{$_ x$\}map{substr$_[0],$_