aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-11-23 10:28:02 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-11-23 10:28:02 +0000
commitb7f6ccb5d687617d8ef2a91a6ad3a46a1139d9b3 (patch)
treeec6acece7ec351df0aadfcdcfedb00916a82587c
parentda7f72157db87a1f448db7f426aeb30b4acbd10f (diff)
downloadperlweeklychallenge-club-b7f6ccb5d687617d8ef2a91a6ad3a46a1139d9b3.tar.gz
perlweeklychallenge-club-b7f6ccb5d687617d8ef2a91a6ad3a46a1139d9b3.tar.bz2
perlweeklychallenge-club-b7f6ccb5d687617d8ef2a91a6ad3a46a1139d9b3.zip
fixing somebits
-rw-r--r--challenge-140/james-smith/perl/ch-1.pl30
-rw-r--r--challenge-140/james-smith/perl/ch-2.pl8
2 files changed, 24 insertions, 14 deletions
diff --git a/challenge-140/james-smith/perl/ch-1.pl b/challenge-140/james-smith/perl/ch-1.pl
index 2129293473..9483b8e9bb 100644
--- a/challenge-140/james-smith/perl/ch-1.pl
+++ b/challenge-140/james-smith/perl/ch-1.pl
@@ -14,17 +14,27 @@ my @TESTS = (
[ [ 100, 11 ] , 111 ],
);
-say DecBin->new($_->[0][0]) + DecBin->new($_->[0][1]) == DecBin->new($_->[1]) ? 'OK' : 'FAIL' foreach @TESTS;
+foreach(@TESTS) {
+ my $x = DecBin->new($_->[0][0]);
+ my $y = DecBin->new($_->[0][1]);
+ my $z = DecBin->new($_->[1]);
+ say join "\t", $x, $y, $x+$y, $z, $x+$y==$z ? 'OK' : 'FAIL';
+}
-say DecBinExp->new($_->[0][0]) + DecBinExp->new($_->[0][1]) == DecBinExp->new($_->[1]) ? 'OK' : 'FAIL' foreach @TESTS;
+foreach(@TESTS) {
+ my $x = DecBinExp->new($_->[0][0]);
+ my $y = DecBinExp->new($_->[0][1]);
+ my $z = DecBinExp->new($_->[1]);
+ say join "\t", $x, $y, $x+$y, $z, $x+$y==$z ? 'OK' : 'FAIL';
+}
package DecBin;
-use overload ('+','bin_add','==','comp');
+use overload ('+'=>'bin_add','=='=>'comp','""'=>'show');
-sub new { return bless \$_[1], $_[0]; }
-
-sub comp { ${$_[0]} == ${$_[1]}; }
+sub new { bless \$_[1], $_[0] }
+sub show { ${$_[0]} }
+sub comp { ${$_[0]} == ${$_[1]} }
sub bin_add {
my($t,$c,$m,$a,$b) = (0,0,1,${$_[0]},${$_[1]});
@@ -34,11 +44,11 @@ sub bin_add {
package DecBinExp;
-use overload ('+','bin_add','==','comp');
-
-sub new { return bless \$_[1], $_[0]; }
+use overload ('+'=>'bin_add','=='=>'comp','""'=>'show');
-sub comp { ${$_[0]} == ${$_[1]}; }
+sub new { bless \$_[1], $_[0] }
+sub show { ${$_[0]} }
+sub comp { ${$_[0]} == ${$_[1]} }
sub bin_add {
my($t,$c,$m,$a,$b) = (0,0,1,${$_[0]},${$_[1]});
diff --git a/challenge-140/james-smith/perl/ch-2.pl b/challenge-140/james-smith/perl/ch-2.pl
index 849f946bb3..dc99f6ad04 100644
--- a/challenge-140/james-smith/perl/ch-2.pl
+++ b/challenge-140/james-smith/perl/ch-2.pl
@@ -18,8 +18,8 @@ my @TESTS = (
[ [3,3,6], 4 ],
);
-is( get_num(@{$_->[0]}), $_->[1] ) foreach @TESTS;
-is( get_num_exp(@{$_->[0]}), $_->[1] ) foreach @TESTS;
+is( get_num(@{$_->[0]}), $_->[1] ) for @TESTS;
+is( get_num_exp(@{$_->[0]}), $_->[1] ) for @TESTS;
done_testing();
@@ -31,8 +31,8 @@ sub get_num {
sub get_num_exp {
my($i,$j,$k,$t,%h) = @_;
- foreach $t (1..$i) {
- $h{$t*$_}++ foreach 1..$j;
+ for $t (1..$i) {
+ $h{$t*$_}++ for 1..$j;
}
for (sort {$a<=>$b} keys %h) {
$k -= $h{$_};