aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-02-08 00:09:42 +0000
committerdrbaggy <js5@sanger.ac.uk>2022-02-08 00:09:42 +0000
commit51f58739137c4fdab173493328641288827acb37 (patch)
treea3e7ac347af68467b91040f113b5e57c71c6adde
parent157edcf24bd47b084350bbe79e8a2212055f70c6 (diff)
downloadperlweeklychallenge-club-51f58739137c4fdab173493328641288827acb37.tar.gz
perlweeklychallenge-club-51f58739137c4fdab173493328641288827acb37.tar.bz2
perlweeklychallenge-club-51f58739137c4fdab173493328641288827acb37.zip
updated last example to avoid direct assign
-rw-r--r--challenge-151/james-smith/README.md2
-rw-r--r--challenge-151/james-smith/perl/ch-2.pl3
2 files changed, 3 insertions, 2 deletions
diff --git a/challenge-151/james-smith/README.md b/challenge-151/james-smith/README.md
index af952bd3f9..7f3a84e2f4 100644
--- a/challenge-151/james-smith/README.md
+++ b/challenge-151/james-smith/README.md
@@ -62,7 +62,7 @@ We keep repeating the 2nd part until we get to the end house - and this gives us
```perl
sub rob {
my @b = shift;
- $b[1] = shift, $b[-1]<$b[-2] && ($b[-1]=$b[-2]) if @_;
+ (push @b,shift ), $b[-1]<$b[-2] && ($b[-1]=$b[-2]) if @_;
(push @b,$_+$b[-2]), $b[-1]<$b[-2] && ($b[-1]=$b[-2]) for @_;
$b[-1];
}
diff --git a/challenge-151/james-smith/perl/ch-2.pl b/challenge-151/james-smith/perl/ch-2.pl
index cd6ae0a042..4f3dbe6db4 100644
--- a/challenge-151/james-smith/perl/ch-2.pl
+++ b/challenge-151/james-smith/perl/ch-2.pl
@@ -21,6 +21,7 @@ my @TESTS = (
);
is( rob( @{$_->[0]}), $_->[1] ) foreach @TESTS;
+is( rob2( @{$_->[0]}), $_->[1] ) foreach @TESTS;
done_testing();
@@ -40,7 +41,7 @@ sub rob {
##
## Comments this way so they don't hide the symmetry of the code
my @b = shift;
- $b[1] = shift, $b[ 1]<$b[ 0] && ($b[ 1]=$b[ 0]) if @_;
+ (push @b,shift ), $b[-1]<$b[-2] && ($b[-1]=$b[-2]) if @_;
(push @b,$_+$b[-2]), $b[-1]<$b[-2] && ($b[-1]=$b[-2]) for @_;
$b[-1];
}