diff options
| author | E. Choroba <choroba@matfyz.cz> | 2020-03-22 00:29:42 +0100 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2020-03-22 00:29:42 +0100 |
| commit | 08da240c07f6996186d5048f7cd43ab5c3bcd435 (patch) | |
| tree | 9b2a050aeb51507fc2dcc6bc86b0f13e59fc515f /challenge-052 | |
| parent | 9d6876b98ab3e21991f72169abc9b2dd1408381b (diff) | |
| download | perlweeklychallenge-club-08da240c07f6996186d5048f7cd43ab5c3bcd435.tar.gz perlweeklychallenge-club-08da240c07f6996186d5048f7cd43ab5c3bcd435.tar.bz2 perlweeklychallenge-club-08da240c07f6996186d5048f7cd43ab5c3bcd435.zip | |
Add link to a blog post by E. Choroba
Also, fix the Lucky Winner according to it: init_arg was 0 instead of
undef and turns were implemented twice.
Diffstat (limited to 'challenge-052')
| -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 { |
