diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-12 01:12:10 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-12 01:12:10 +0000 |
| commit | df43e3cc5c295537271b14c59a4e82c03908b162 (patch) | |
| tree | 8ab366b08f0cf127127feae675277bb1846c591f | |
| parent | f223b1cd9a2464a1609bb2076eba3d13304bc0f3 (diff) | |
| parent | e3c5cd9da79849dfa376e45d5a1dcf9579357363 (diff) | |
| download | perlweeklychallenge-club-df43e3cc5c295537271b14c59a4e82c03908b162.tar.gz perlweeklychallenge-club-df43e3cc5c295537271b14c59a4e82c03908b162.tar.bz2 perlweeklychallenge-club-df43e3cc5c295537271b14c59a4e82c03908b162.zip | |
Merge pull request #3229 from gnustavo/095
095 - Gustavo Chaves solutions
| -rwxr-xr-x | challenge-095/gustavo-chaves/is-palindrome.pl | 11 | ||||
| -rwxr-xr-x | challenge-095/gustavo-chaves/stack.pl | 53 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-095/gustavo-chaves/is-palindrome.pl b/challenge-095/gustavo-chaves/is-palindrome.pl new file mode 100755 index 0000000000..dd56d937c9 --- /dev/null +++ b/challenge-095/gustavo-chaves/is-palindrome.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/ +# TASK #1 › Palindrome Number + +use 5.030; +use warnings; + +my $N = shift; + +say $N eq reverse($N) ? 1 : 0; diff --git a/challenge-095/gustavo-chaves/stack.pl b/challenge-095/gustavo-chaves/stack.pl new file mode 100755 index 0000000000..6ddfaedd7a --- /dev/null +++ b/challenge-095/gustavo-chaves/stack.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-095/ +# TASK #2 › Demo Stack + +use 5.030; +use warnings; +use List::Util; + +package Stack { + + sub new { + my $class = shift; + + return bless [], $class; + } + + sub push { + my ($self, $n) = @_; + + push @$self, $n; + return; + } + + sub pop { + my ($self) = @_; + + return pop @$self; + } + + sub top { + my ($self) = @_; + + return $self->[-1]; + } + + sub min { + my ($self) = @_; + + return List::Util::min @$self; + } + +}; + + +my $stack = Stack->new; +$stack->push(2); +$stack->push(-1); +$stack->push(0); +$stack->pop; # removes 0 +say $stack->top; # prints -1 +$stack->push(0); +say $stack->min; # prints -1 |
