diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-03-21 23:41:10 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-21 23:41:10 +0000 |
| commit | ffe0ab50a9da64583170bb88ea2016a55099cedc (patch) | |
| tree | 9b2a050aeb51507fc2dcc6bc86b0f13e59fc515f | |
| parent | 9d6876b98ab3e21991f72169abc9b2dd1408381b (diff) | |
| parent | 08da240c07f6996186d5048f7cd43ab5c3bcd435 (diff) | |
| download | perlweeklychallenge-club-ffe0ab50a9da64583170bb88ea2016a55099cedc.tar.gz perlweeklychallenge-club-ffe0ab50a9da64583170bb88ea2016a55099cedc.tar.bz2 perlweeklychallenge-club-ffe0ab50a9da64583170bb88ea2016a55099cedc.zip | |
Merge pull request #1437 from choroba/ech052b
Add link to a blog post by E. Choroba
| -rw-r--r-- | challenge-052/e-choroba/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-052/e-choroba/perl/ch-2.pl | 13 |
2 files changed, 6 insertions, 8 deletions
diff --git a/challenge-052/e-choroba/blog.txt b/challenge-052/e-choroba/blog.txt new file mode 100644 index 0000000000..b0aaf80605 --- /dev/null +++ b/challenge-052/e-choroba/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/e_choroba/2020/03/perl-weekly-challenge-052-stepping-numbers-lucky-winner.html diff --git a/challenge-052/e-choroba/perl/ch-2.pl b/challenge-052/e-choroba/perl/ch-2.pl index 72d7ad51c9..50a77ba035 100755 --- a/challenge-052/e-choroba/perl/ch-2.pl +++ b/challenge-052/e-choroba/perl/ch-2.pl @@ -15,7 +15,8 @@ remaining coins is only £1.88. { package My::Game; use Moo; - has [qw[ player1 player2 ]] => (is => 'rw', default => 0, init_arg => 0); + has [qw[ player1 player2 ]] => ( + is => 'rw', default => 0, init_arg => undef); has coins => (is => 'ro', required => 1); has remaining => (is => 'rw', lazy => 1, builder => 'coins'); @@ -24,18 +25,14 @@ remaining coins is only £1.88. if (1 == @{ $self->remaining } || $self->remaining->[0] == 200 ) { - $self->player1($self->player1 - + shift @{ $self->remaining }); + $self->turn('l'); } elsif ($self->remaining->[-1] == 200 || $self->remaining->[1] == 200 ) { - $self->player1($self->player1 - + pop @{ $self->remaining }); + $self->turn('r'); } else { - $self->player1($self->player1 - + shift @{ $self->remaining }); + $self->turn('l'); }; - $self->switch; } sub turn { |
