aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2021-08-30 11:37:48 +0100
committerJames Smith <js5@sanger.ac.uk>2021-08-30 11:37:48 +0100
commitf2d64b2a58b676cc8ec2231c2b9d2ab6fb4c18bf (patch)
tree64f561c847d60fb6b8b7fc7536911980693bc545
parent154cd35be8cff200829935f4278c9ff289be3362 (diff)
downloadperlweeklychallenge-club-f2d64b2a58b676cc8ec2231c2b9d2ab6fb4c18bf.tar.gz
perlweeklychallenge-club-f2d64b2a58b676cc8ec2231c2b9d2ab6fb4c18bf.tar.bz2
perlweeklychallenge-club-f2d64b2a58b676cc8ec2231c2b9d2ab6fb4c18bf.zip
Pushed minor changes and tidied code
-rw-r--r--challenge-128/james-smith/README.md32
-rw-r--r--challenge-128/james-smith/perl/ch-2.pl3
2 files changed, 16 insertions, 19 deletions
diff --git a/challenge-128/james-smith/README.md b/challenge-128/james-smith/README.md
index 66d70d3fa2..be4fb1ed86 100644
--- a/challenge-128/james-smith/README.md
+++ b/challenge-128/james-smith/README.md
@@ -118,18 +118,16 @@ Here we use a little used concept in perl the label "`OUTER`" - this allows our
sub bump_platform {
my @arr = @{shift @_};
my @dep = @{shift @_};
- my @plat = ();
+ my @platforms = ();
OUTER: foreach my $st (@arr) {
- foreach(0..$#plat) {
- next unless $st gt $plat[$_];
- $plat[$_] = shift @dep;
- next OUTER;
+ foreach(0..$#platforms) {
+ ($platforms[$_] = shift @dep) && (next OUTER)
+ if $st gt $platforms[$_];
}
- push @plat, shift @dep;
+ push @platforms,shift @dep;
}
- return scalar @plat;
+ return scalar @platforms;
}
-
```
**Notes:
@@ -140,17 +138,17 @@ We can also keep information about which trains are on by re-writing what is sto
sub bump_platform_keep_trains {
my @arr = @{shift @_};
my @dep = @{shift @_};
- my $t = 0;
- my @plat; # = ( [ [shift @{$arr}, shift @{$dep}, my $t=1] ] );
+ my($train_no, @platforms) = (0);
+
OUTER: foreach my $st (@arr) {
- foreach(@plat) {
- next unless $st gt $_->[-1][1];
- push @{$_}, [ $st, (shift @dep), ++$t ];
- next OUTER;
+ foreach(@platforms) {
+ (push @{$_}, [ $st, (shift @dep), ++$train_no ]) &&
+ (next OUTER) if $st gt $_->[-1][1];
}
- push @plat, [ [ $st, (shift @dep), ++$t ] ];
+ push @platforms, [ [ $st, (shift @dep), ++$train_no ] ];
}
- say ' ', join ' ', map { "Train $_->[2]: $_->[0]-$_->[1]" } @{$_} foreach @plat;
- return scalar @plat;
+ say ' ', join ' ', map { "Train $_->[2]: $_->[0]-$_->[1]" } @{$_}
+ foreach @platforms;
+ return scalar @platforms;
}
```
diff --git a/challenge-128/james-smith/perl/ch-2.pl b/challenge-128/james-smith/perl/ch-2.pl
index bbda141d19..34a31da1f3 100644
--- a/challenge-128/james-smith/perl/ch-2.pl
+++ b/challenge-128/james-smith/perl/ch-2.pl
@@ -25,8 +25,7 @@ done_testing();
sub bump_platform {
my @arr = @{shift @_};
my @dep = @{shift @_};
- #shift @{$arr};
- my @platforms = ();#(shift @{$dep});
+ my @platforms = ();
OUTER: foreach my $st (@arr) {
foreach(0..$#platforms) {
## If train fits on platform - we extend the last departure time